#/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. 洛谷 题解 P1772 【[ZJOI2006]物流运输】

    题目描述 物流公司要把一批货物从码头\(A\)运到码头\(B\).由于货物量比较大,需要\(n\)天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过 ...

  2. PCA分析的疑问

    R 与python scikit-learn PCA的主成分结果有部分是反的 通过R和python分别计算出来的PCA的结果存在某些主成分的结果是相反的,这些结果是没有问题的,只是表示这个分量被反转了 ...

  3. DCEP究竟是什么?

    DCEP (Digital Currency Electronic Payment) 数字货币电子支付工具 DCEP将由中国人民银行推出,推出时间待定. DCEP是使用区块链技术的一种联盟链,为全新的 ...

  4. ~jmeter解决csrftoken登录问题

    一.登录接口 url:http://192.168.163.128:/user/login/ 请求方法:post 请求参数: account:用户名 password:登录密码 remember:是否 ...

  5. 最小轻量级的Istio来了,仅使用流量治理能力

    Istio 1.0.1作为8月份的版本已经发布,主要修复了1.0版本发布以来发现的一些关键Issue.官网的release note(https://istio.io/about/notes/1.0. ...

  6. 代码质量控制 & 编程注意项

    目录 代码质量控制 编程注意项 代码&功能优化 代码优化 功能&模块优化 其他 小技巧 调试 用于记录工作中出现的问题和编程时需要注意的重点,保证代码质量和编程效率     代码质量控 ...

  7. C++ 异步编程:Boost.Asio

    Boost.Asio 是一个用于网络和低级 I/O 编程的跨平台 C++ 库,它使用现代 C++ 方法为开发人员提供一致的异步模型 一个异步使用计时器的样例 #include <iostream ...

  8. Singer House CodeForces - 830D (组合计数,dp)

    大意: 一个$k$层完全二叉树, 每个节点向它祖先连边, 就得到一个$k$房子, 求$k$房子的所有简单路径数. $DP$好题. 首先设$dp_{i,j}$表示$i$房子, 分出$j$条简单路径的方案 ...

  9. OSS服务和自建服务器存储对比

    1 OSS 1.1 什么是OSS   阿里云对象存储服务(Object Storage Service,简称OSS),是阿里云提供的海量.安全.低成本.高可靠的云存储服务.它是一个分布式的对象存储服务 ...

  10. sqlserver导入Excel数据 总是报错:错误 0xc020901c: 数据流任务 1: 输出“Excel 源输出”(55) 上的 输出列“T2”(64) 出错。返回的列状态是:“文本被截断,或者一个或多个字符在目标代码页中没有匹配项

    在网络上搜索解决办法,解决办法是把excel导入到access数据库中,再把access数据库导入到sqlsever中,公司机器上不让安装office工具,问了一个同事得到的回答是把数据中很长的那行数 ...