backup_setup.sh 18 KB

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