ask confirm shell
#/bin/bash
BASEDIR=$(cd $(dirname $) && pwd)
cd $BASEDIR>/dev/null
usage="Usage: $0 -o/--org orgId[Must] -p/--prepare t[Option] -f/--force t[Option] -d/--dry t[Option]"
force=
prepare=
step=
dry=
RED='\033[0;31m'
BLUE='\033[1;32m'
GREEN='\033[1;34m'
NC='\033[0m' # No Color
#read input parameters
while [ "$1" != "" ]
do
case $ in
-o|--org) shift
orgId=$
;;
-f|--force) shift
if [ "$1" = "-p" ];then
prepare=
fi
force=
;;
-p|--prepare) shift
if [ "$1" = "-f" ];then
force=
fi
prepare=
;;
-d|--dry) shift
dry=
;;
*) echo $usage
exit
;;
esac
shift
done
if [ -z $orgId ];then
echo -e "$RED[Error] Missing orgId!$NC\r\n$usage"
exit
fi
logsdir=logs/${orgId}_`date +'%Y-%m-%d-%H-%M-%S'`
mkdir -p $logsdir
log="$logsdir/csc_migrage_$orgId.log" check_and_commit()
{
cmd=""
step=`expr "$step" + `
echo ""|tee -a $logs
echo -e "$BLUE[`date +'%Y-%m-%d %H:%M:%S'`][Step $step] exec $1 $NC"|tee -a $log
if [ $force -eq ];then
while true; do
read -p "Do you confirm to execute step $1? [y/n]" yn
case $yn in
[Yy]* )
$;
if [ $dry -eq ];then
echo -e "$GREEN [Dry Run]$NC $cmd"|tee -a $log
else
echo $cmd|tee -a $log
$cmd|tee $logsdir/$.log
fi
break;;
[Nn]* ) echo "ignore step $1"|tee -a $log ;break;;
esac
done
else
$
if [ $dry -eq ];then
echo -e "$GREEN [Dry Run]$NC $cmd"|tee -a $log
else
echo $cmd|tee -a $log
$cmd|tee -a $logsdir/$.log
fi
fi
} prepare_message_confirm()
{
echo "Please make sure next items be done"
echo -e "${RED} 1.env.sh use correct environment information ${NC}"
echo -e "${RED} 2.all gcs vm had added the onecloud replay URL and restarted${NC}"
echo -e "${RED} 3.make sure this vm can connect to brown field mongo/redshift/CMC gateway ${NC}"
echo -e "${RED} 4.had startup cloud-subscriber with correct version and expose port 3424 ${NC}"
echo -e "${RED} 5.brown field subscrbier-sync pod had patched ${NC}"
if [ $force -eq ];then
while true; do
read -p "Do you confirm ? [y/n]" yn
case $yn in
[Yy]* ) echo "will continue to execute for org :$orgId";break;;
[Nn]* ) exit - ;break;;
esac
done
fi } migrate_mongo_big_collections()
{
cmd="python ./mongo_to_psql_sxaccfs.py -m $compass_mongo -n $onecloud_postgres_host -d $onecloud_postgres_db -u $onecloud_postgres_username -p $onecloud_postgres_password"
} mongo_to_postgres_noorg()
{
cmd="python ./mongo_to_psql.py -m $compass_mongo -n $onecloud_postgres_host -d $onecloud_postgres_db -u $onecloud_postgres_username -p $onecloud_postgres_password --no-org"
} brown_sub_fullsync()
{
cmd="curl -s $old_subscriber_api/sync?orgid=$orgId&mode=fsync-es&save-sync-logs=false&async=false"
} mongo_to_postgres_relay()
{
cmd="python ./mongo_to_psql.py -m $compass_mongo -n $onecloud_postgres_host -d $onecloud_postgres_db -u $onecloud_postgres_username -p $onecloud_postgres_password -O $orgId -i in_collection_names.txt"
} sub_clean()
{
cmd="curl -s $local_subscriber_api/migrate-clear?orgId=$orgId"
} sub_soc()
{
cmd="curl -s $local_subscriber_api/migrate-usoc?orgId=$orgId"
} sub_cc()
{
cmd="curl -s $local_subscriber_api/migrate-subscriber-cc?orgId=$orgId"
} sub_billing()
{
cmd="curl -s $local_subscriber_api/migrate-subscriber-billing?orgId=$orgId"
} sub_update_fee()
{
cmd="curl -s $local_subscriber_api/calc-usoc-fee?orgId=$orgId"
} sub_reindex()
{
cmd="curl -s $onecloud_subscriber_api/index/reindex?org=$orgId"
} acs_relay()
{
sed -i "3i\ \"oneCloudRelay\": true," org_$orgId.json
cat org_$orgId.json|tee -a $log
cmd="curl -s -X PUT -d @org_$orgId.json --url http://$old_gcs_ipaddress:8081/cc/organization/$orgId"
} check_org_exists()
{
curl -s http://$old_gcs_ipaddress:8081/cc/organization/$orgId>org_$orgId.json
if [ `cat org_$orgId.json|grep 'No organization found'|wc -l` -eq ];then
echo -e "$RED org:$orgId is not exist! $NC"
rm -rf org_$orgId.json
exit -
fi
if [ `cat org_$orgId.json|grep oneCloudRelay|grep true|wc -l` -eq ];then
if [ $force -eq ];then
while true; do
read -p "org:$orgId had already relay,Do you want to continue? [y/n]" yn
case $yn in
[Yy]* )
sed -i '/oneCloudRelay/d' org_$orgId.json;
echo "will continue to execute for org :$orgId";
break;;
[Nn]* ) exit - ;break;;
esac
done
else
sed -i '/oneCloudRelay/d' org_$orgId.json
fi
fi
} acs_workflow()
{
cmd="curl -s -X POST --url http://$onecloud_gcs_ipaddress:8081/cc/workflow/audit?orgId=$orgId"
} mongo_to_postgres_cloud()
{
cmd="python ./mongo_to_psql.py -m $cloud_mongo -n $onecloud_postgres_host -d $onecloud_postgres_db -u $onecloud_postgres_username -p $onecloud_postgres_password -O $orgId"
} mongo_to_postgres_compass_others()
{
cmd="python ./mongo_to_psql.py -m $compass_mongo -n $onecloud_postgres_host -d $onecloud_postgres_db -u $onecloud_postgres_username -p $onecloud_postgres_password -O $orgId -e ex_collection_names.txt"
} mongo_to_mongo()
{
cmd="./migrate_mongo_to_mongo.sh $orgId"
} copy_cc_org()
{
cmd="curl -s -X POST -d @org_$orgId.json --url http://$onecloud_gcs_ipaddress:8081/cc/organization/$orgId"
} main()
{
if [ $force -eq ];then
prepare_message_confirm
fi
if [ $prepare -eq ];then
check_and_commit "Migrate2BigCollectionOfMongo" migrate_mongo_big_collections
check_and_commit "Mongo2PostgresCrossOrgFiles" mongo_to_postgres_noorg
fi
check_org_exists
# check_and_commit "Mongo2Postgres cross org files" mongo_to_postgres_noorg
check_and_commit "BrownSubscriberFullSync" brown_sub_fullsync
check_and_commit "MigrateCompassMongoforACSRelay" mongo_to_postgres_relay
check_and_commit "SubscriberMigrateClean" sub_clean
check_and_commit "SubscriberMigrateUSOC" sub_soc
check_and_commit "SubscriberMigrateCCSubscribers" sub_cc
check_and_commit "SubscriberMigrateBilling" sub_billing
check_and_commit "SubscriberMigrateFEE" sub_update_fee
check_and_commit "GreenSubscriberReindex" sub_reindex
check_and_commit "MigrateCCorgToGreen" copy_cc_org
check_and_commit "EnableACSRelay" acs_relay
check_and_commit "MigrateACSWorkflow" acs_workflow
check_and_commit "CopyALLCloudCollectionsMongo2Postgres" mongo_to_postgres_cloud
check_and_commit "CopyLeftCompassCollectionsMongo2Postgres" mongo_to_postgres_compass_others
check_and_commit "MigrateCloudMongoToNewCloudMongo" mongo_to_mongo
}
source env.sh
main
ask confirm shell的更多相关文章
- SSH Secure Shell Client的windows客户端样式设置
SSH Secure Shell Client下载:http://pan.baidu.com/s/1dF2lDdf 其他工具(putty-0.67)下载:http://pan.baidu.com/s/ ...
- shell之函数
function 所有函数在使用前必须定义.这意味着必须将函数放在脚本开始部分,直至shell解释器首次发现它时,才可以使用.调用函数仅使用其函数名即可.可以将函数看作是脚本中的一段代码,但是有一个主 ...
- Shell 备忘录
此文收集工作中用到的Shell备忘,随用随机: 1.比较 -eq 等于,如:if [ "$a" -eq "$b" ] -ne 不等于,如 ...
- linux自动启动shell和init概述(fedora use systemmd now!!!)
linux运行级别 linux启动之后会在一个级别运行,下面列出了这些运行级别: 0 系统停止 1 单用户系统,不需要登陆 2 多用户系统但不支持NFS,命令行模式登陆 3 完整多用户模式,命令行模 ...
- Managing linux Shell Jobs
Managing Shell Jobs When moving jobs between the foreground and background, it may be useful to ha ...
- Unix / 类 Unix shell 中有哪些很酷很冷门很少用很有用的命令?(转)
著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:孙立伟 链接:http://www.zhihu.com/question/20140085/answer/14107336 ...
- 基于ssh,shell,python,iptables,fabric,supervisor和模板文件的多服务器配置管理
前言:略 新服务器:NS 主服务器:OS 一:OS上新建模板目录例如 mkdir bright 用于导入一些不方便在远程修改的配置文件.redis.conf等,到需要配置的步骤时用远程cp命令覆 ...
- shell脚本小案例
1.获取远程ftp数据到本地目录 #!/bin/bash ftp -n<<! open 135.0.24.19 user exchange exchange binary cd /idep ...
- Linux Shell编程参考大全
本文记录Linux Shell编程中常用基本知识,方便快速入门以及查询使用. 本文主要分为以下几个部分: 一.Shell中的变量 任何编程语言中,有关变量的定义,作用范围,赋值等都是最最基础的知识. ...
随机推荐
- nohup保证程序后台运行
前言 我们运行某些命令的时候,它会默认在前台执行.如果要进行其他操作,则需要先停掉此程序.然后就蛋疼了. 解决 碰到这种情况,我们可以使用"nohup"命令和"&am ...
- vmware linux 硬盘空间不足时增加硬盘并挂载
不同的版本的vmware在设置界面中可能稍有不同,基本是一致的. 还有一种方式是扩展,这里没有记录,扩展时需要在虚拟机关机状态下. 1.选择在vmware中点击设置并打开,将光标定位在hard Dis ...
- Win10使用Xmanager6远程桌面连接CentOS7服务器
服务器:CentOS 7.6 GNOME桌面环境(若最小化安装,默认是无桌面的,那么就要安装桌面,参考百度) 个人主机:Windows 10专业版,请安装Xmanager Power Suite 6( ...
- JUC之AbstractQueuedSynchronizer原理分析 - 独占/共享模式
1. 简介 AbstractQueuedSynchronizer (抽象队列同步器,以下简称 AQS)出现在 JDK 1.5 中,由大师 Doug Lea 所创作.AQS 是很多同步器的基础框架. R ...
- hadoop常见问题收集
hadoop 搭建 常用命令记录 快捷键安装在/user/local/bin目录下 nano 文件名 ctrl + k 剪切一行 ctrl + o 保存并重命名,不重命名直接enter ctrl + ...
- Tomcat报错:No result type specified for result named 'success'
今天学Struts, tomcat报出了异常信息 Exception starting filter [struts2] Unable to load configuration.还有 No resu ...
- (一)构建基于ubuntu docker MySQL 5.6 镜像并推送到Docker Hub
一,创建目录二,文件准备三,构建四,使用五,在宿主机上连接docker 中的mysql六,推送镜像到Docker hub 一,创建目录 mkdir -p mysql/5.6 二,文件准备 注意执行脚本 ...
- ansible使用普通用户免密登陆+sudo提权
前提:从ansible控制端使用test用户可以免密登陆所有被控制端,并且被控端test用户支持sudo提权 # ansible主机清单 cat /etc/ansible/hosts [online- ...
- WUSTOJ 1326: Graph(Java)费马数
题目链接:1326: Graph 参考博客:HNUSTOJ-1617 Graph(费马数)--G2MI Description Your task is to judge whether a regu ...
- SRID (空间引用识别号, 坐标系)【转】
SRID (空间引用识别号, 坐标系)-云栖社区-阿里云 Spatial Reference List -- Spatial Reference Chapter 8. PostGIS Referenc ...