backup_setup.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  11. clear
  12. printf "
  13. #######################################################################
  14. # OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+ #
  15. # Setup the backup parameters #
  16. # For more information please visit https://oneinstack.com #
  17. #######################################################################
  18. "
  19. # Check if user is root
  20. [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  21. oneinstack_dir=$(dirname "`readlink -f $0`")
  22. pushd ${oneinstack_dir} > /dev/null
  23. . ./options.conf
  24. . ./versions.txt
  25. . ./include/color.sh
  26. . ./include/check_os.sh
  27. . ./include/check_dir.sh
  28. . ./include/download.sh
  29. . ./include/python.sh
  30. while :; do echo
  31. echo 'Please select your backup destination:'
  32. echo -e "\t${CMSG}1${CEND}. Localhost"
  33. echo -e "\t${CMSG}2${CEND}. Remote host"
  34. echo -e "\t${CMSG}3${CEND}. Aliyun OSS"
  35. echo -e "\t${CMSG}4${CEND}. Qcloud COS"
  36. echo -e "\t${CMSG}5${CEND}. UPYUN"
  37. echo -e "\t${CMSG}6${CEND}. QINIU"
  38. read -e -p "Please input numbers:(Default 1 press Enter) " desc_bk
  39. desc_bk=${desc_bk:-'1'}
  40. array_desc=(${desc_bk})
  41. array_all=(1 2 3 4 5 6)
  42. for v in ${array_desc[@]}
  43. do
  44. [ -z "`echo ${array_all[@]} | grep -w ${v}`" ] && desc_flag=1
  45. done
  46. if [ "${desc_flag}" == '1' ]; then
  47. unset desc_flag
  48. echo; echo "${CWARNING}input error! Please only input number 1 3 4 and so on${CEND}"; echo
  49. continue
  50. else
  51. break
  52. fi
  53. done
  54. sed -i 's@^backup_destination=.*@backup_destination=@' ./options.conf
  55. [ -n `echo ${desc_bk} | grep -w 1` ] && sed -i 's@^backup_destination=.*@backup_destination=local@' ./options.conf
  56. [ -n `echo ${desc_bk} | grep -w 2` ] && sed -i 's@^backup_destination=.*@&,remote@' ./options.conf
  57. [ -n `echo ${desc_bk} | grep -w 3` ] && sed -i 's@^backup_destination=.*@&,oss@' ./options.conf
  58. [ -n `echo ${desc_bk} | grep -w 4` ] && sed -i 's@^backup_destination=.*@&,cos@' ./options.conf
  59. [ -n `echo ${desc_bk} | grep -w 5` ] && sed -i 's@^backup_destination=.*@&,upyun@' ./options.conf
  60. [ -n `echo ${desc_bk} | grep -w 6` ] && sed -i 's@^backup_destination=.*@&,qiniu@' ./options.conf
  61. sed -i 's@^backup_destination=,@backup_destination=@' ./options.conf
  62. while :; do echo
  63. echo 'Please select your backup content:'
  64. echo -e "\t${CMSG}1${CEND}. Only Database"
  65. echo -e "\t${CMSG}2${CEND}. Only Website"
  66. echo -e "\t${CMSG}3${CEND}. Database and Website"
  67. read -e -p "Please input a number:(Default 1 press Enter) " content_bk
  68. content_bk=${content_bk:-1}
  69. if [[ ! ${content_bk} =~ ^[1-3]$ ]]; then
  70. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  71. else
  72. break
  73. fi
  74. done
  75. [ "${content_bk}" == '1' ] && sed -i 's@^backup_content=.*@backup_content=db@' ./options.conf
  76. [ "${content_bk}" == '2' ] && sed -i 's@^backup_content=.*@backup_content=web@' ./options.conf
  77. [ "${content_bk}" == '3' ] && sed -i 's@^backup_content=.*@backup_content=db,web@' ./options.conf
  78. if [[ ${desc_bk} =~ ^[1,2]$ ]]; then
  79. while :; do echo
  80. echo "Please enter the directory for save the backup file: "
  81. read -e -p "(Default directory: ${backup_dir}): " new_backup_dir
  82. new_backup_dir=${new_backup_dir:-${backup_dir}}
  83. if [ -z "`echo ${new_backup_dir}| grep '^/'`" ]; then
  84. echo "${CWARNING}input error! ${CEND}"
  85. else
  86. break
  87. fi
  88. done
  89. sed -i "s@^backup_dir=.*@backup_dir=${new_backup_dir}@" ./options.conf
  90. fi
  91. while :; do echo
  92. echo "Please enter a valid backup number of days: "
  93. read -e -p "(Default days: 5): " expired_days
  94. expired_days=${expired_days:-5}
  95. [ -n "`echo ${expired_days} | sed -n "/^[0-9]\+$/p"`" ] && break || echo "${CWARNING}input error! Please only enter numbers! ${CEND}"
  96. done
  97. sed -i "s@^expired_days=.*@expired_days=${expired_days}@" ./options.conf
  98. if [ "${content_bk}" != '2' ]; then
  99. databases=`${db_install_dir}/bin/mysql -uroot -p$dbrootpwd -e "show databases\G" | grep Database | awk '{print $2}' | grep -Evw "(performance_schema|information_schema|mysql|sys)"`
  100. while :; do echo
  101. echo "Please enter one or more name for database, separate multiple database names with commas: "
  102. read -e -p "(Default database: `echo $databases | tr ' ' ','`) " db_name
  103. db_name=`echo ${db_name} | tr -d ' '`
  104. [ -z "${db_name}" ] && db_name="`echo $databases | tr ' ' ','`"
  105. D_tmp=0
  106. for D in `echo ${db_name} | tr ',' ' '`
  107. do
  108. [ -z "`echo $databases | grep -w $D`" ] && { echo "${CWARNING}$D was not exist! ${CEND}" ; D_tmp=1; }
  109. done
  110. [ "$D_tmp" != '1' ] && break
  111. done
  112. sed -i "s@^db_name=.*@db_name=${db_name}@" ./options.conf
  113. fi
  114. if [ "${content_bk}" != '1' ]; then
  115. websites=`ls ${wwwroot_dir}`
  116. while :; do echo
  117. echo "Please enter one or more name for website, separate multiple website names with commas: "
  118. read -e -p "(Default website: `echo $websites | tr ' ' ','`) " website_name
  119. website_name=`echo ${website_name} | tr -d ' '`
  120. [ -z "${website_name}" ] && website_name="`echo $websites | tr ' ' ','`"
  121. W_tmp=0
  122. for W in `echo ${website_name} | tr ',' ' '`
  123. do
  124. [ ! -e "${wwwroot_dir}/$W" ] && { echo "${CWARNING}${wwwroot_dir}/$W not exist! ${CEND}" ; W_tmp=1; }
  125. done
  126. [ "$W_tmp" != '1' ] && break
  127. done
  128. sed -i "s@^website_name=.*@website_name=${website_name}@" ./options.conf
  129. fi
  130. echo
  131. echo "You have to backup the content:"
  132. [ "${content_bk}" != '2' ] && echo "Database: ${CMSG}${db_name}${CEND}"
  133. [ "${content_bk}" != '1' ] && echo "Website: ${CMSG}${website_name}${CEND}"
  134. if [ -n `echo ${desc_bk} | grep -w 2` ]; then
  135. > tools/iplist.txt
  136. while :; do echo
  137. read -e -p "Please enter the remote host ip: " remote_ip
  138. [ -z "${remote_ip}" -o "${remote_ip}" == '127.0.0.1' ] && continue
  139. echo
  140. read -e -p "Please enter the remote host port(Default: 22) : " remote_port
  141. remote_port=${remote_port:-22}
  142. echo
  143. read -e -p "Please enter the remote host user(Default: root) : " remote_user
  144. remote_user=${remote_user:-root}
  145. echo
  146. read -e -p "Please enter the remote host password: " remote_password
  147. IPcode=$(echo "ibase=16;$(echo "${remote_ip}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  148. Portcode=$(echo "ibase=16;$(echo "${remote_port}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  149. PWcode=$(echo "ibase=16;$(echo "$remote_password" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  150. [ -e "~/.ssh/known_hosts" ] && grep ${remote_ip} ~/.ssh/known_hosts | sed -i "/${remote_ip}/d" ~/.ssh/known_hosts
  151. ./tools/mssh.exp ${IPcode}P ${remote_user} ${PWcode}P ${Portcode}P true 10
  152. if [ $? -eq 0 ]; then
  153. [ -z "`grep ${remote_ip} tools/iplist.txt`" ] && echo "${remote_ip} ${remote_port} ${remote_user} $remote_password" >> tools/iplist.txt || echo "${CWARNING}${remote_ip} has been added! ${CEND}"
  154. while :; do
  155. read -e -p "Do you want to add more host ? [y/n]: " morehost_yn
  156. if [[ ! ${morehost_yn} =~ ^[y,n]$ ]]; then
  157. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  158. else
  159. break
  160. fi
  161. done
  162. [ "${morehost_yn}" == 'n' ] && break
  163. fi
  164. done
  165. fi
  166. if [ -n `echo ${desc_bk} | grep -w 3` ]; then
  167. if [ ! -e "/usr/local/bin/ossutil" ]; then
  168. wget -qc http://gosspublic.alicdn.com/ossutil/1.4.2/ossutil${OS_BIT} -O /usr/local/bin/ossutil
  169. chmod +x /usr/local/bin/ossutil
  170. fi
  171. while :; do echo
  172. echo 'Please select your backup aliyun datacenter:'
  173. echo -e "\t ${CMSG}1${CEND}. cn-hangzhou-华东 1 (杭州) ${CMSG}2${CEND}. cn-shanghai-华东 2 (上海)"
  174. echo -e "\t ${CMSG}3${CEND}. cn-qingdao-华北 1 (青岛) ${CMSG}4${CEND}. cn-beijing-华北 2 (北京)"
  175. echo -e "\t ${CMSG}5${CEND}. cn-zhangjiakou-华北 3 (张家口) ${CMSG}6${CEND}. cn-huhehaote-华北 5(呼和浩特)"
  176. echo -e "\t ${CMSG}7${CEND}. cn-shenzhen-华南 1 (深圳) ${CMSG}8${CEND}. cn-hongkong-香港"
  177. echo -e "\t ${CMSG}9${CEND}. us-west-美西 1 (硅谷) ${CMSG}10${CEND}. us-east-美东 1 (弗吉尼亚)"
  178. echo -e "\t${CMSG}11${CEND}. ap-southeast-亚太东南 1 (新加坡) ${CMSG}12${CEND}. ap-southeast-亚太东南 2 (悉尼)"
  179. echo -e "\t${CMSG}13${CEND}. ap-southeast-亚太东南 3 (吉隆坡) ${CMSG}14${CEND}. ap-southeast-亚太东南 5 (雅加达)"
  180. echo -e "\t${CMSG}15${CEND}. ap-northeast-亚太东北 1 (日本) ${CMSG}16${CEND}. ap-south-亚太南部 1 (孟买)"
  181. echo -e "\t${CMSG}17${CEND}. eu-central-欧洲中部 1 (法兰克福) ${CMSG}18${CEND}. me-east-中东东部 1 (迪拜)"
  182. read -e -p "Please input a number:(Default 1 press Enter) " Location
  183. Location=${Location:-1}
  184. if [[ "${Location}" =~ ^[1-9]$|^1[0-8]$ ]]; then
  185. break
  186. else
  187. echo "${CWARNING}input error! Please only input number 1~18${CEND}"
  188. fi
  189. done
  190. [ "${Location}" == '1' ] && Host=oss-cn-hangzhou-internal.aliyuncs.com
  191. [ "${Location}" == '2' ] && Host=oss-cn-shanghai-internal.aliyuncs.com
  192. [ "${Location}" == '3' ] && Host=oss-cn-qingdao-internal.aliyuncs.com
  193. [ "${Location}" == '4' ] && Host=oss-cn-beijing-internal.aliyuncs.com
  194. [ "${Location}" == '5' ] && Host=oss-cn-zhangjiakou-internal.aliyuncs.com
  195. [ "${Location}" == '6' ] && Host=oss-cn-huhehaote-internal.aliyuncs.com
  196. [ "${Location}" == '7' ] && Host=oss-cn-shenzhen-internal.aliyuncs.com
  197. [ "${Location}" == '8' ] && Host=oss-cn-hongkong-internal.aliyuncs.com
  198. [ "${Location}" == '9' ] && Host=oss-us-west-1-internal.aliyuncs.com
  199. [ "${Location}" == '10' ] && Host=oss-us-east-1-internal.aliyuncs.com
  200. [ "${Location}" == '11' ] && Host=oss-ap-southeast-1-internal.aliyuncs.com
  201. [ "${Location}" == '12' ] && Host=oss-ap-southeast-2-internal.aliyuncs.com
  202. [ "${Location}" == '13' ] && Host=oss-ap-southeast-3-internal.aliyuncs.com
  203. [ "${Location}" == '14' ] && Host=oss-ap-southeast-5-internal.aliyuncs.com
  204. [ "${Location}" == '15' ] && Host=oss-ap-northeast-1-internal.aliyuncs.com
  205. [ "${Location}" == '16' ] && Host=oss-ap-south-1-internal.aliyuncs.com
  206. [ "${Location}" == '17' ] && Host=oss-eu-central-1-internal.aliyuncs.com
  207. [ "${Location}" == '18' ] && Host=oss-me-east-1-internal.aliyuncs.com
  208. [ "$(./include/check_port.py ${Host} 80)" == "False" ] && Host=`echo ${Host} | sed 's@-internal@@g'`
  209. [ -e "/root/.ossutilconfig" ] && rm -f /root/.ossutilconfig
  210. while :; do echo
  211. read -e -p "Please enter the aliyun oss Access Key ID: " KeyID
  212. [ -z "${KeyID}" ] && continue
  213. echo
  214. read -e -p "Please enter the aliyun oss Access Key Secret: " KeySecret
  215. [ -z "${KeySecret}" ] && continue
  216. /usr/local/bin/ossutil ls -e ${Host} -i ${KeyID} -k ${KeySecret} >/dev/null 2>&1
  217. if [ $? -eq 0 ];then
  218. /usr/local/bin/ossutil config -e ${Host} -i ${KeyID} -k ${KeySecret} >/dev/null 2>&1
  219. while :; do echo
  220. read -e -p "Please enter the aliyun oss bucket: " Bucket
  221. /usr/local/bin/ossutil mb oss://${Bucket} >/dev/null 2>&1
  222. [ $? -eq 0 ] && { echo "${CMSG}[${Bucket}] createbucket OK${CEND}"; sed -i "s@^oss_bucket=.*@oss_bucket=${Bucket}@" ./options.conf; break; } || echo "${CWARNING}[${Bucket}] already exists, You need to use the OSS Console to create a bucket for storing.${CEND}"
  223. done
  224. break
  225. fi
  226. done
  227. fi
  228. if [ -n `echo ${desc_bk} | grep -w 4` ]; then
  229. Install_Python
  230. [ ! -e "${python_install_dir}/lib/coscmd" ] && ${python_install_dir}/bin/pip install coscmd >/dev/null 2>&1
  231. while :; do echo
  232. echo 'Please select your backup qcloud datacenter:'
  233. echo -e "\t ${CMSG} 1${CEND}. ap-beijing-1-北京一区(华北) ${CMSG}2${CEND}. ap-beijing-北京"
  234. echo -e "\t ${CMSG} 3${CEND}. ap-shanghai-上海(华东) ${CMSG}4${CEND}. ap-guangzhou-广州(华南)"
  235. echo -e "\t ${CMSG} 5${CEND}. ap-chengdu-成都(西南) ${CMSG}6${CEND}. ap-chongqing-重庆"
  236. echo -e "\t ${CMSG} 7${CEND}. ap-singapore-新加坡 ${CMSG}8${CEND}. ap-hongkong-香港"
  237. echo -e "\t ${CMSG} 9${CEND}. na-toronto-多伦多 ${CMSG}10${CEND}. eu-frankfurt-法兰克福"
  238. echo -e "\t ${CMSG}11${CEND}. ap-mumbai-孟买 ${CMSG}12${CEND}. ap-seoul-首尔"
  239. echo -e "\t ${CMSG}13${CEND}. na-siliconvalley-硅谷 ${CMSG}14${CEND}. na-ashburn-弗吉尼亚"
  240. echo -e "\t ${CMSG}15${CEND}. ap-bangkok-曼谷 ${CMSG}16${CEND}. eu-moscow-莫斯科"
  241. echo -e "\t ${CMSG}17${CEND}. ap-tokyo-东京"
  242. read -e -p "Please input a number:(Default 1 press Enter) " Location
  243. Location=${Location:-1}
  244. if [[ "${Location}" =~ ^[1-9]$|^1[0-7]$ ]]; then
  245. break
  246. else
  247. echo "${CWARNING}input error! Please only input number 1~17${CEND}"
  248. fi
  249. done
  250. [ "${Location}" == '1' ] && REGION='ap-beijing-1'
  251. [ "${Location}" == '2' ] && REGION='ap-beijing'
  252. [ "${Location}" == '3' ] && REGION='ap-shanghai'
  253. [ "${Location}" == '4' ] && REGION='ap-guangzhou'
  254. [ "${Location}" == '5' ] && REGION='ap-chengdu'
  255. [ "${Location}" == '6' ] && REGION='ap-chongqing'
  256. [ "${Location}" == '7' ] && REGION='ap-singapore'
  257. [ "${Location}" == '8' ] && REGION='ap-hongkong'
  258. [ "${Location}" == '9' ] && REGION='na-toronto'
  259. [ "${Location}" == '10' ] && REGION='eu-frankfurt'
  260. [ "${Location}" == '11' ] && REGION='ap-mumbai'
  261. [ "${Location}" == '12' ] && REGION='ap-seoul'
  262. [ "${Location}" == '13' ] && REGION='na-siliconvalley'
  263. [ "${Location}" == '14' ] && REGION='na-ashburn'
  264. [ "${Location}" == '15' ] && REGION='ap-bangkok'
  265. [ "${Location}" == '16' ] && REGION='eu-moscow'
  266. [ "${Location}" == '17' ] && REGION='ap-tokyo'
  267. while :; do echo
  268. read -e -p "Please enter the Qcloud COS APPID: " APPID
  269. [[ ! "${APPID}" =~ ^[0-9]+$ ]] && { echo "${CWARNING}input error, must be a number${CEND}"; continue; }
  270. echo
  271. read -e -p "Please enter the Qcloud COS SECRET_ID: " SECRET_ID
  272. [ -z "${SECRET_ID}" ] && continue
  273. echo
  274. read -e -p "Please enter the Qcloud COS SECRET_KEY: " SECRET_KEY
  275. [ -z "${SECRET_KEY}" ] && continue
  276. echo
  277. read -e -p "Please enter the Qcloud COS BUCKET: " BUCKET
  278. if [[ ${BUCKET} =~ "-${APPID}"$ ]]; then
  279. Bucket=${BUCKET}
  280. else
  281. [ -z "${BUCKET}" ] && continue
  282. echo
  283. Bucket=${BUCKET}-${APPID}
  284. fi
  285. ${python_install_dir}/bin/coscmd config -u ${APPID} -a ${SECRET_ID} -s ${SECRET_KEY} -r ${REGION} -b ${Bucket} >/dev/null 2>&1
  286. ${python_install_dir}/bin/coscmd list >/dev/null 2>&1
  287. if [ $? -eq 0 ];then
  288. echo "${CMSG}APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET OK${CEND}"
  289. echo
  290. break
  291. else
  292. ${python_install_dir}/bin/coscmd -b ${Bucket} createbucket >/dev/null 2>&1
  293. if [ $? -eq 0 ];then
  294. echo "${CMSG}APPID/SECRET_ID/SECRET_KEY/REGION OK, You createbucket ${Bucket}${CEND}"
  295. echo
  296. break
  297. else
  298. echo "${CWARNING}input error! APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET invalid${CEND}"
  299. continue
  300. fi
  301. fi
  302. done
  303. fi
  304. if [ -n `echo ${desc_bk} | grep -w 5` ]; then
  305. if [ ! -e "/usr/local/bin/upx" ]; then
  306. if [ "${OS_BIT}" == '64' ]; then
  307. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx-linux-amd64-v0.2.3 -O /usr/local/bin/upx
  308. elif [ "${OS_BIT}" == '32' ]; then
  309. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx-linux-386-v0.2.3 -O /usr/local/bin/upx
  310. fi
  311. chmod +x /usr/local/bin/upx
  312. fi
  313. while :; do echo
  314. read -e -p "Please enter the upyun ServiceName: " ServiceName
  315. [ -z "${ServiceName}" ] && continue
  316. echo
  317. read -e -p "Please enter the upyun Operator: " Operator
  318. [ -z "${Operator}" ] && continue
  319. echo
  320. read -e -p "Please enter the upyun Password: " Password
  321. [ -z "${Password}" ] && continue
  322. echo
  323. /usr/local/bin/upx login ${ServiceName} ${Operator} ${Password} >/dev/null 2>&1
  324. if [ $? = 0 ]; then
  325. echo "${CMSG}ServiceName/Operator/Password OK${CEND}"
  326. echo
  327. break
  328. else
  329. echo "${CWARNING}input error! ServiceName/Operator/Password invalid${CEND}"
  330. fi
  331. done
  332. fi
  333. if [ -n `echo ${desc_bk} | grep -w 6` ]; then
  334. if [ ! -e "/usr/local/bin/qrsctl" ]; then
  335. if [ "${OS_BIT}" == '64' ]; then
  336. wget -qc http://devtools.qiniu.com/linux/amd64/qrsctl -O /usr/local/bin/qrsctl
  337. elif [ "${OS_BIT}" == '32' ]; then
  338. wget -qc http://devtools.qiniu.com/linux/386/qrsctl -O /usr/local/bin/qrsctl
  339. fi
  340. chmod +x /usr/local/bin/qrsctl
  341. fi
  342. if [ ! -e "/usr/local/bin/qshell" ]; then
  343. wget -qc http://devtools.qiniu.com/qshell-v2.3.5.zip -O /tmp/qshell-v2.3.5.zip
  344. unzip -q /tmp/qshell-v2.3.5.zip -d /tmp/
  345. if [ "${OS_BIT}" == '64' ]; then
  346. /bin/cp /tmp/qshell-linux-x64 /usr/local/bin/qshell
  347. elif [ "${OS_BIT}" == '32' ]; then
  348. /bin/cp /tmp/qshell-linux-x86 /usr/local/bin/qshell
  349. fi
  350. chmod +x /usr/local/bin/qshell
  351. rm -f /tmp/qshell*
  352. fi
  353. while :; do echo
  354. echo 'Please select your backup qiniu datacenter:'
  355. echo -e "\t ${CMSG} 1${CEND}. 华东 ${CMSG}2${CEND}. 华北"
  356. echo -e "\t ${CMSG} 3${CEND}. 华南 ${CMSG}4${CEND}. 北美"
  357. echo -e "\t ${CMSG} 5${CEND}. 东南亚"
  358. read -e -p "Please input a number:(Default 1 press Enter) " Location
  359. Location=${Location:-1}
  360. if [[ "${Location}" =~ ^[1-5]$ ]]; then
  361. break
  362. else
  363. echo "${CWARNING}input error! Please only input number 1~5${CEND}"
  364. fi
  365. done
  366. [ "${Location}" == '1' ] && zone='z0'
  367. [ "${Location}" == '2' ] && zone='z1'
  368. [ "${Location}" == '3' ] && zone='z2'
  369. [ "${Location}" == '4' ] && zone='na0'
  370. [ "${Location}" == '5' ] && zone='as0'
  371. while :; do echo
  372. read -e -p "Please enter the qiniu AccessKey: " AccessKey
  373. [ -z "${AccessKey}" ] && continue
  374. echo
  375. read -e -p "Please enter the qiniu SecretKey: " SecretKey
  376. [ -z "${SecretKey}" ] && continue
  377. echo
  378. read -e -p "Please enter the qiniu bucket: " Bucket
  379. [ -z "${Bucket}" ] && continue
  380. echo
  381. /usr/local/bin/qshell account ${AccessKey} ${SecretKey}
  382. /usr/local/bin/qrsctl login ${AccessKey} ${SecretKey}
  383. if /usr/local/bin/qrsctl bucketinfo ${Bucket} > /dev/null 2>&1; then
  384. sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${Bucket}@" ./options.conf
  385. echo "${CMSG}AccessKey/SecretKey OK${CEND}"
  386. echo
  387. break
  388. elif /usr/local/bin/qrsctl mkbucket ${Bucket} ${zone} > /dev/null 2>&1; then
  389. /usr/local/bin/qrsctl private ${Bucket} 1
  390. echo "${CMSG}[${Bucket}] createbucket OK${CEND}"
  391. sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${Bucket}@" ./options.conf
  392. echo "${CMSG}AccessKey/SecretKey OK${CEND}"
  393. echo
  394. break
  395. else
  396. echo "${CWARNING}input error! AccessKey/SecretKey invalid${CEND}"
  397. fi
  398. done
  399. fi