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中的变量 任何编程语言中,有关变量的定义,作用范围,赋值等都是最最基础的知识. ...
随机推荐
- JVM(四) 垃圾回收
1. 堆内存结构 Java堆从GC的角度可以细分为:新生代(Eden区.From Survivor区和To Survivor区)和老年代. 1.1 新生代 新生代是用来存放新生的对象.一般占据堆的1/ ...
- Beginning Linux Programming 学习--chapter 17 Programming KDE using QT
KDE: KDE,K桌面环境(K Desktop Environment)的缩写.一种著名的运行于 Linux.Unix 以及FreeBSD 等操作系统上的自由图形桌面环境,整个系统采用的都是 Tro ...
- ABP中的本地化处理(下)
在上篇文章中我们的重点是讲述怎样通过在Domain层通过PreInitialize()配置ILocalizationConfiguration中的Sources(IList<ILocalizat ...
- IdentityServer4 学习三
ClientCredentials客户端类型实现 客户端应用向IdentityServer请求AccessToken,IdentityServer验证通过把AccessToken返回给客户端应用,客户 ...
- 题解 Luogu P1110 【[ZJOI2007]报表统计】
感谢 @cmy962085349 提供的hack数据,已经改对了. 先声明,我好像是题解里写双$fhq$ $treap$里唯一能过的...(最后两个点啊) 思路:首先看题目,$MIN_GAP_SORT ...
- js new到底做了什么?如何重写new?(转)
转自:https://blog.csdn.net/lyt_angularjs/article/details/86623988
- hdu 1242 不用标记数组的深搜
#include<stdio.h>#include<string.h>char mapp[220][220];int m,n,mmin;void dfs(int x,int y ...
- git 修改注释
原文:https://www.jianshu.com/p/098d85a58bf1 修改最后一条注释: git commit --amend 如果已经推送到远程,强制push到远程仓库: git pu ...
- 这些方面做好了才能叫运营-App运营日常
现在APP的开发推广是时代的潮流,同时也是不少企业的难题.现在我们就来谈谈APP运营的一些问题. 1. 基础运营正常维护产品最日常.最普通的工作,如APP应用包在各大应用市场提交上传等,如安卓渠道,包 ...
- OpenStack kilo版(7) 部署dashboard
安装dashboard root@controller:~# apt-get install openstack-dashboard 配置 /etc/openstack-dashboard/loc ...