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中的变量 任何编程语言中,有关变量的定义,作用范围,赋值等都是最最基础的知识. ...
随机推荐
- python 线程队列LifoQueue-LIFO(36)
在 python线程队列Queue-FIFO 文章中已经介绍了 先进先出队列Queue,而今天给大家介绍的是第二种:线程队列LifoQueue-LIFO,数据先进后出类型,两者有什么区别呢? 一.队 ...
- Echarts dataZoom 区域缩放
dataZoom=[ //区域缩放 { id: 'dataZoomX', show:true, //是否显示 组件.如果设置为 false,不会显示,但是数据过滤的功能还存在. backgroundC ...
- 利用Anaconda软件安装opencv模块
先说明我安装opencv环境的原因:因为我Anaconda中创建了tensorflow和pytorch虚拟环境,想在每个虚拟环境下都安装opencv模块,这样在后期进行代码调试的时候更加便捷,以下是我 ...
- C++ 重载运算符返回值 和 返回引用的原因
原因是: +,-,*等返回不了引用,比如+运算符,可以如下重载(为了简单,假设A 只有int x:int y) A operator+(A a,A b) {A sum; sum.x=a.x+b.x ...
- python 之 前端开发( DOM操作)
11.47 DOM操作 查找节点: 11.471 直接查找 document.getElementById //根据ID获取唯一一个标签 document.getElementsByClassName ...
- C++标识符的作用域与可见性
一.标识符的作用域与可见性 作用域讨论的是标识符的有效范围,可见性讨论的是标识符是否可以被引用. 二.作用域 作用域是一个标识符在程序正文中有效的区域.C++中标识符的作用域有函数原型作用域.局部作用 ...
- Hadoop 求单词count数
package com.yw.hadoop273; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongW ...
- 用Onenote写博客日志
进入OneNote,选中要发布博客的分区,然后点击菜单栏中的[文件]->[发送]->[发送至博客] 这时候会启动word程序弹出下面的对话框(如果你从未设置过),点击[立即 ...
- zabbix添加自定义监控(自动发现)遇到的问题
问题:zabbix添加自动发现端口,提示Value should be a JSON object [root@localhost zabbix_agentd.d]# zabbix_get -s 19 ...
- Angular 学习笔记 (cdk focus monitor 和一些 focus tabindex 的基础)
更新 : 2019-12-22 focusInitialElementWhenReady 我们经常会调用到这个方法, 它的逻辑是这样 先看有没有 cdkFocusInitial 有的就 focus ...