#/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的更多相关文章

  1. SSH Secure Shell Client的windows客户端样式设置

    SSH Secure Shell Client下载:http://pan.baidu.com/s/1dF2lDdf 其他工具(putty-0.67)下载:http://pan.baidu.com/s/ ...

  2. shell之函数

    function 所有函数在使用前必须定义.这意味着必须将函数放在脚本开始部分,直至shell解释器首次发现它时,才可以使用.调用函数仅使用其函数名即可.可以将函数看作是脚本中的一段代码,但是有一个主 ...

  3. Shell 备忘录

    此文收集工作中用到的Shell备忘,随用随机: 1.比较 -eq       等于,如:if [ "$a" -eq "$b" ] -ne       不等于,如 ...

  4. linux自动启动shell和init概述(fedora use systemmd now!!!)

    linux运行级别  linux启动之后会在一个级别运行,下面列出了这些运行级别: 0 系统停止 1 单用户系统,不需要登陆 2 多用户系统但不支持NFS,命令行模式登陆 3 完整多用户模式,命令行模 ...

  5. Managing linux Shell Jobs

    Managing Shell Jobs   When moving jobs between the foreground and background, it may be useful to ha ...

  6. Unix / 类 Unix shell 中有哪些很酷很冷门很少用很有用的命令?(转)

    著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:孙立伟 链接:http://www.zhihu.com/question/20140085/answer/14107336 ...

  7. 基于ssh,shell,python,iptables,fabric,supervisor和模板文件的多服务器配置管理

     前言:略 新服务器:NS   主服务器:OS 一:OS上新建模板目录例如 mkdir bright 用于导入一些不方便在远程修改的配置文件.redis.conf等,到需要配置的步骤时用远程cp命令覆 ...

  8. shell脚本小案例

    1.获取远程ftp数据到本地目录 #!/bin/bash ftp -n<<! open 135.0.24.19 user exchange exchange binary cd /idep ...

  9. Linux Shell编程参考大全

    本文记录Linux Shell编程中常用基本知识,方便快速入门以及查询使用. 本文主要分为以下几个部分: 一.Shell中的变量 任何编程语言中,有关变量的定义,作用范围,赋值等都是最最基础的知识. ...

随机推荐

  1. mysql查看正在运行的语句

    mysql查看正在运行的语句 并且查看运行最多的mysql语句 MySQL 打开 general log 后,所有的查询语句都会记录在 general log 文件,文件为只读方式,但这样genera ...

  2. Go资源被墙最快解决方案

    原文链接:https://juejin.im/post/5cd945946fb9a032060c47a3,补充,最新的1.13版本go里默认就是用go module,直接设置代理即可: 注:如果没法升 ...

  3. linux 给运行程序指定动态库路径

    1. 连接和运行时库文件搜索路径到设置 库文件在连接(静态库和共享 库)和运行(仅限于使用共享库的程序)时被使用,其搜索路径是在系统中进行设置的.一般 Linux 系统把 /lib 和 /usr/li ...

  4. PHP与Memcached服务器交互的分布式实现源码分析

    转自: http://blog.csdn.net/hguisu/article/details/7353595 前段时间,因为一个项目的关系,研究了php通过调用memcache和memcached ...

  5. LeetCode 70. 爬楼梯(Climbing Stairs)

    70. 爬楼梯 70. Climbing Stairs 题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意: 给定 ...

  6. 《Mysql - 幻读》

    一:准备 - 为了深入了解幻读,准备数据. CREATE TABLE `t` ( `id` ) NOT NULL, `c` ) DEFAULT NULL, `d` ) DEFAULT NULL, PR ...

  7. C++ enable_if 模板特化实例(函数返回值特化、函数参数特化、模板参数特化、模板重载)

    1. enable_if 原理 关于 enable_if 原理这里就不细说了,网上有很多,可以参考如下教程,这里只讲解用法实例,涵盖常规使用全部方法. 文章1 文章2 文章3 1. 所需头文件 #in ...

  8. WUSTOJ 1304: 最大最小公倍数(Java)

    题目链接:

  9. hadoop 节点退役和服役

    节点的服役和退役(hdfs)---------------------- 黑白名单的组合情况-------------------------include //dfs.includeexclude ...

  10. element-ui里的form校验,一直有点疑惑,prop是怎么对应的?

    图一 图一中红框内的这种校验,必须在 这个product_form数据域内定义对应的变量名(cid.itemName......),不然对应不上. 图一红框外的那种校验,则不用在数据域内定义对应的变量 ...