1
0

backup_setup.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  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 7+ Debian 9+ and Ubuntu 16+ #
  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. echo -e "\t${CMSG}7${CEND}. Amazon S3"
  39. echo -e "\t${CMSG}8${CEND}. Dropbox"
  40. read -e -p "Please input numbers:(Default 1 press Enter) " desc_bk
  41. desc_bk=${desc_bk:-'1'}
  42. array_desc=(${desc_bk})
  43. array_all=(1 2 3 4 5 6 7 8)
  44. for v in ${array_desc[@]}
  45. do
  46. [ -z "`echo ${array_all[@]} | grep -w ${v}`" ] && desc_flag=1
  47. done
  48. if [ "${desc_flag}" == '1' ]; then
  49. unset desc_flag
  50. echo; echo "${CWARNING}input error! Please only input number 1 3 4 and so on${CEND}"; echo
  51. continue
  52. else
  53. sed -i 's@^backup_destination=.*@backup_destination=@' ./options.conf
  54. break
  55. fi
  56. done
  57. [ -n "`echo ${desc_bk} | grep -w 1`" ] && sed -i 's@^backup_destination=.*@backup_destination=local@' ./options.conf
  58. [ -n "`echo ${desc_bk} | grep -w 2`" ] && sed -i 's@^backup_destination=.*@&,remote@' ./options.conf
  59. [ -n "`echo ${desc_bk} | grep -w 3`" ] && sed -i 's@^backup_destination=.*@&,oss@' ./options.conf
  60. [ -n "`echo ${desc_bk} | grep -w 4`" ] && sed -i 's@^backup_destination=.*@&,cos@' ./options.conf
  61. [ -n "`echo ${desc_bk} | grep -w 5`" ] && sed -i 's@^backup_destination=.*@&,upyun@' ./options.conf
  62. [ -n "`echo ${desc_bk} | grep -w 6`" ] && sed -i 's@^backup_destination=.*@&,qiniu@' ./options.conf
  63. [ -n "`echo ${desc_bk} | grep -w 7`" ] && sed -i 's@^backup_destination=.*@&,s3@' ./options.conf
  64. [ -n "`echo ${desc_bk} | grep -w 8`" ] && sed -i 's@^backup_destination=.*@&,dropbox@' ./options.conf
  65. sed -i 's@^backup_destination=,@backup_destination=@' ./options.conf
  66. while :; do echo
  67. echo 'Please select your backup content:'
  68. echo -e "\t${CMSG}1${CEND}. Only Database"
  69. echo -e "\t${CMSG}2${CEND}. Only Website"
  70. echo -e "\t${CMSG}3${CEND}. Database and Website"
  71. read -e -p "Please input a number:(Default 1 press Enter) " content_bk
  72. content_bk=${content_bk:-1}
  73. if [[ ! ${content_bk} =~ ^[1-3]$ ]]; then
  74. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  75. else
  76. break
  77. fi
  78. done
  79. [ "${content_bk}" == '1' ] && sed -i 's@^backup_content=.*@backup_content=db@' ./options.conf
  80. [ "${content_bk}" == '2' ] && sed -i 's@^backup_content=.*@backup_content=web@' ./options.conf
  81. [ "${content_bk}" == '3' ] && sed -i 's@^backup_content=.*@backup_content=db,web@' ./options.conf
  82. if [ -n "`echo ${desc_bk} | grep -Ew '1|2'`" ]; then
  83. while :; do echo
  84. echo "Please enter the directory for save the backup file: "
  85. read -e -p "(Default directory: ${backup_dir}): " new_backup_dir
  86. new_backup_dir=${new_backup_dir:-${backup_dir}}
  87. if [ -z "`echo ${new_backup_dir}| grep '^/'`" ]; then
  88. echo "${CWARNING}input error! ${CEND}"
  89. else
  90. break
  91. fi
  92. done
  93. sed -i "s@^backup_dir=.*@backup_dir=${new_backup_dir}@" ./options.conf
  94. fi
  95. while :; do echo
  96. echo "Please enter a valid backup number of days: "
  97. read -e -p "(Default days: 5): " expired_days
  98. expired_days=${expired_days:-5}
  99. [ -n "`echo ${expired_days} | sed -n "/^[0-9]\+$/p"`" ] && break || echo "${CWARNING}input error! Please only enter numbers! ${CEND}"
  100. done
  101. sed -i "s@^expired_days=.*@expired_days=${expired_days}@" ./options.conf
  102. if [ "${content_bk}" != '2' ]; then
  103. 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)"`
  104. while :; do echo
  105. echo "Please enter one or more name for database, separate multiple database names with commas: "
  106. read -e -p "(Default database: `echo $databases | tr ' ' ','`) " db_name
  107. db_name=`echo ${db_name} | tr -d ' '`
  108. [ -z "${db_name}" ] && db_name="`echo $databases | tr ' ' ','`"
  109. D_tmp=0
  110. for D in `echo ${db_name} | tr ',' ' '`
  111. do
  112. [ -z "`echo $databases | grep -w $D`" ] && { echo "${CWARNING}$D was not exist! ${CEND}" ; D_tmp=1; }
  113. done
  114. [ "$D_tmp" != '1' ] && break
  115. done
  116. sed -i "s@^db_name=.*@db_name=${db_name}@" ./options.conf
  117. fi
  118. if [ "${content_bk}" != '1' ]; then
  119. websites=`ls ${wwwroot_dir}`
  120. while :; do echo
  121. echo "Please enter one or more name for website, separate multiple website names with commas: "
  122. read -e -p "(Default website: `echo $websites | tr ' ' ','`) " website_name
  123. website_name=`echo ${website_name} | tr -d ' '`
  124. [ -z "${website_name}" ] && website_name="`echo $websites | tr ' ' ','`"
  125. W_tmp=0
  126. for W in `echo ${website_name} | tr ',' ' '`
  127. do
  128. [ ! -e "${wwwroot_dir}/$W" ] && { echo "${CWARNING}${wwwroot_dir}/$W not exist! ${CEND}" ; W_tmp=1; }
  129. done
  130. [ "$W_tmp" != '1' ] && break
  131. done
  132. sed -i "s@^website_name=.*@website_name=${website_name}@" ./options.conf
  133. fi
  134. echo
  135. echo "You have to backup the content:"
  136. [ "${content_bk}" != '2' ] && echo "Database: ${CMSG}${db_name}${CEND}"
  137. [ "${content_bk}" != '1' ] && echo "Website: ${CMSG}${website_name}${CEND}"
  138. if [ -n "`echo ${desc_bk} | grep -w 2`" ]; then
  139. > tools/iplist.txt
  140. while :; do echo
  141. read -e -p "Please enter the remote host address: " remote_address
  142. [ -z "${remote_address}" -o "${remote_address}" == '127.0.0.1' ] && continue
  143. echo
  144. read -e -p "Please enter the remote host port(Default: 22) : " remote_port
  145. remote_port=${remote_port:-22}
  146. echo
  147. read -e -p "Please enter the remote host user(Default: root) : " remote_user
  148. remote_user=${remote_user:-root}
  149. echo
  150. read -e -p "Please enter the remote host password: " remote_password
  151. IPcode=$(echo "ibase=16;$(echo "${remote_address}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  152. Portcode=$(echo "ibase=16;$(echo "${remote_port}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  153. PWcode=$(echo "ibase=16;$(echo "$remote_password" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  154. [ -e "~/.ssh/known_hosts" ] && grep ${remote_address} ~/.ssh/known_hosts | sed -i "/${remote_address}/d" ~/.ssh/known_hosts
  155. ./tools/mssh.exp ${IPcode}P ${remote_user} ${PWcode}P ${Portcode}P true 10
  156. if [ $? -eq 0 ]; then
  157. [ -z "`grep ${remote_address} tools/iplist.txt`" ] && echo "${remote_address} ${remote_port} ${remote_user} $remote_password" >> tools/iplist.txt || echo "${CWARNING}${remote_address} has been added! ${CEND}"
  158. while :; do
  159. read -e -p "Do you want to add more host ? [y/n]: " morehost_flag
  160. if [[ ! ${morehost_flag} =~ ^[y,n]$ ]]; then
  161. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  162. else
  163. break
  164. fi
  165. done
  166. [ "${morehost_flag}" == 'n' ] && break
  167. fi
  168. done
  169. fi
  170. if [ -n "`echo ${desc_bk} | grep -w 3`" ]; then
  171. if [ ! -e "/usr/local/bin/ossutil" ]; then
  172. if [ "${armplatform}" == 'y' ]; then
  173. wget -qc https://gosspublic.alicdn.com/ossutil/1.7.10/ossutilarm64 -O /usr/local/bin/ossutil
  174. else
  175. wget -qc https://gosspublic.alicdn.com/ossutil/1.7.10/ossutil64 -O /usr/local/bin/ossutil
  176. fi
  177. chmod +x /usr/local/bin/ossutil
  178. fi
  179. while :; do echo
  180. echo 'Please select your backup aliyun datacenter:'
  181. echo -e "\t ${CMSG}1${CEND}. cn-hangzhou-华东1 (杭州) ${CMSG}2${CEND}. cn-shanghai-华东2 (上海)"
  182. echo -e "\t ${CMSG}3${CEND}. cn-qingdao-华北1 (青岛) ${CMSG}4${CEND}. cn-beijing-华北2 (北京)"
  183. echo -e "\t ${CMSG}5${CEND}. cn-zhangjiakou-华北3 (张家口) ${CMSG}6${CEND}. cn-huhehaote-华北5(呼和浩特)"
  184. echo -e "\t ${CMSG}7${CEND}. cn-wulanchabu-华北6(乌兰察布) ${CMSG}8${CEND}. cn-shenzhen-华南1(深圳)"
  185. echo -e "\t ${CMSG}9${CEND}. cn-heyuan-华南2(河源) ${CMSG}10${CEND}. cn-guangzhou-华南3(广州)"
  186. echo -e "\t${CMSG}11${CEND}. cn-chengdu-西南1(成都) ${CMSG}12${CEND}. cn-hongkong-香港"
  187. echo -e "\t${CMSG}13${CEND}. us-west-1-美国(硅谷) ${CMSG}14${CEND}. us-east-1-美国(弗吉尼亚)"
  188. echo -e "\t${CMSG}15${CEND}. ap-southeast-1-新加坡 ${CMSG}16${CEND}. ap-southeast-2-澳大利亚(悉尼)"
  189. echo -e "\t${CMSG}17${CEND}. ap-southeast-3-马来西亚(吉隆坡)${CMSG}18${CEND}. ap-southeast-5-印度尼西亚(雅加达)"
  190. echo -e "\t${CMSG}19${CEND}. ap-northeast-1-日本(东京) ${CMSG}20${CEND}. ap-south-1-印度(孟买)"
  191. echo -e "\t${CMSG}21${CEND}. eu-central-1-德国(法兰克福) ${CMSG}22${CEND}. eu-west-1-英国(伦敦)"
  192. echo -e "\t${CMSG}23${CEND}. me-east-1-中东东部 (迪拜) ${CMSG}24${CEND}. ap-southeast-6-菲律宾(马尼拉)"
  193. read -e -p "Please input a number:(Default 1 press Enter) " Location
  194. Location=${Location:-1}
  195. if [[ "${Location}" =~ ^[1-9]$|^1[0-9]$|^24$ ]]; then
  196. break
  197. else
  198. echo "${CWARNING}input error! Please only input number 1~24${CEND}"
  199. fi
  200. done
  201. [ "${Location}" == '1' ] && Host=oss-cn-hangzhou-internal.aliyuncs.com
  202. [ "${Location}" == '2' ] && Host=oss-cn-shanghai-internal.aliyuncs.com
  203. [ "${Location}" == '3' ] && Host=oss-cn-qingdao-internal.aliyuncs.com
  204. [ "${Location}" == '4' ] && Host=oss-cn-beijing-internal.aliyuncs.com
  205. [ "${Location}" == '5' ] && Host=oss-cn-zhangjiakou-internal.aliyuncs.com
  206. [ "${Location}" == '6' ] && Host=oss-cn-huhehaote-internal.aliyuncs.com
  207. [ "${Location}" == '7' ] && Host=oss-cn-wulanchabu-internal.aliyuncs.com
  208. [ "${Location}" == '8' ] && Host=oss-cn-shenzhen-internal.aliyuncs.com
  209. [ "${Location}" == '9' ] && Host=oss-cn-heyuan-internal.aliyuncs.com
  210. [ "${Location}" == '10' ] && Host=oss-cn-guangzhou-internal.aliyuncs.com
  211. [ "${Location}" == '11' ] && Host=oss-cn-chengdu-internal.aliyuncs.com
  212. [ "${Location}" == '12' ] && Host=oss-cn-hongkong-internal.aliyuncs.com
  213. [ "${Location}" == '13' ] && Host=oss-us-west-1-internal.aliyuncs.com
  214. [ "${Location}" == '14' ] && Host=oss-us-east-1-internal.aliyuncs.com
  215. [ "${Location}" == '15' ] && Host=oss-ap-southeast-1-internal.aliyuncs.com
  216. [ "${Location}" == '16' ] && Host=oss-ap-southeast-2-internal.aliyuncs.com
  217. [ "${Location}" == '17' ] && Host=oss-ap-southeast-3-internal.aliyuncs.com
  218. [ "${Location}" == '18' ] && Host=oss-ap-southeast-5-internal.aliyuncs.com
  219. [ "${Location}" == '19' ] && Host=oss-ap-northeast-1-internal.aliyuncs.com
  220. [ "${Location}" == '20' ] && Host=oss-ap-south-1-internal.aliyuncs.com
  221. [ "${Location}" == '21' ] && Host=oss-eu-central-1-internal.aliyuncs.com
  222. [ "${Location}" == '22' ] && Host=oss-eu-west-1-internal.aliyuncs.com
  223. [ "${Location}" == '23' ] && Host=oss-me-east-1-internal.aliyuncs.com
  224. [ "${Location}" == '24' ] && Host=oss-ap-southeast-6-internal.aliyuncs.com
  225. [ "$(./include/check_port.py ${Host} 80)" == "False" ] && Host=`echo ${Host} | sed 's@-internal@@g'`
  226. [ -e "/root/.ossutilconfig" ] && rm -f /root/.ossutilconfig
  227. while :; do echo
  228. read -e -p "Please enter the aliyun oss Access Key ID: " KeyID
  229. [ -z "${KeyID}" ] && continue
  230. echo
  231. read -e -p "Please enter the aliyun oss Access Key Secret: " KeySecret
  232. [ -z "${KeySecret}" ] && continue
  233. /usr/local/bin/ossutil ls -e ${Host} -i ${KeyID} -k ${KeySecret} > /dev/null 2>&1
  234. if [ $? -eq 0 ]; then
  235. /usr/local/bin/ossutil config -e ${Host} -i ${KeyID} -k ${KeySecret} > /dev/null 2>&1
  236. while :; do echo
  237. read -e -p "Please enter the aliyun oss bucket: " OSS_BUCKET
  238. /usr/local/bin/ossutil mb oss://${OSS_BUCKET} > /dev/null 2>&1
  239. if [ $? -eq 0 ]; then
  240. echo "${CMSG}Bucket oss://${OSS_BUCKET}/ created${CEND}"
  241. sed -i "s@^oss_bucket=.*@oss_bucket=${OSS_BUCKET}@" ./options.conf
  242. break
  243. else
  244. echo "${CWARNING}[${OSS_BUCKET}] already exists, You need to use the OSS Console to create a bucket for storing.${CEND}"
  245. fi
  246. done
  247. break
  248. fi
  249. done
  250. fi
  251. if [ -n "`echo ${desc_bk} | grep -w 4`" ]; then
  252. Install_Python
  253. [ ! -e "${python_install_dir}/bin/coscmd" ] && ${python_install_dir}/bin/pip install coscmd > /dev/null 2>&1
  254. while :; do echo
  255. echo 'Please select your backup qcloud datacenter:'
  256. echo -e "\t ${CMSG} 1${CEND}. ap-beijing-1-北京一区(华北) ${CMSG}2${CEND}. ap-beijing-北京"
  257. echo -e "\t ${CMSG} 3${CEND}. ap-nanjing-南京 ${CMSG}4${CEND}. ap-shanghai-上海"
  258. echo -e "\t ${CMSG} 5${CEND}. ap-guangzhou-广州 ${CMSG}6${CEND}. ap-chengdu-成都"
  259. echo -e "\t ${CMSG} 7${CEND}. ap-chongqing-重庆 ${CMSG}8${CEND}. ap-shenzhen-fsi-深圳金融"
  260. echo -e "\t ${CMSG} 9${CEND}. ap-shanghai-fsi-上海金融 ${CMSG}10${CEND}. ap-beijing-fsi-北京金融"
  261. echo -e "\t ${CMSG}11${CEND}. ap-hongkong-香港 ${CMSG}11${CEND}. ap-singapore-新加坡"
  262. echo -e "\t ${CMSG}13${CEND}. ap-mumbai-孟买 ${CMSG}14${CEND}. ap-jakarta-雅加达"
  263. echo -e "\t ${CMSG}15${CEND}. ap-seoul-首尔 ${CMSG}16${CEND}. ap-bangkok-曼谷"
  264. echo -e "\t ${CMSG}17${CEND}. ap-tokyo-东京 ${CMSG}18${CEND}. na-siliconvalley-硅谷(美西)"
  265. echo -e "\t ${CMSG}19${CEND}. na-ashburn-弗吉尼亚(美东) ${CMSG}20${CEND}. na-toronto-多伦多"
  266. echo -e "\t ${CMSG}21${CEND}. sa-saopaulo-圣保罗 ${CMSG}22${CEND}. eu-frankfurt-法兰克福"
  267. echo -e "\t ${CMSG}23${CEND}. eu-moscow-莫斯科"
  268. read -e -p "Please input a number:(Default 1 press Enter) " Location
  269. Location=${Location:-1}
  270. if [[ "${Location}" =~ ^[1-9]$|^1[0-9]$|^2[0-3]$ ]]; then
  271. break
  272. else
  273. echo "${CWARNING}input error! Please only input number 1~23${CEND}"
  274. fi
  275. done
  276. [ "${Location}" == '1' ] && REGION='ap-beijing-1'
  277. [ "${Location}" == '2' ] && REGION='ap-beijing'
  278. [ "${Location}" == '3' ] && REGION='ap-nanjing'
  279. [ "${Location}" == '4' ] && REGION='ap-shanghai'
  280. [ "${Location}" == '5' ] && REGION='ap-guangzhou'
  281. [ "${Location}" == '6' ] && REGION='ap-chengdu'
  282. [ "${Location}" == '7' ] && REGION='ap-chongqing'
  283. [ "${Location}" == '8' ] && REGION='ap-shenzhen-fsi'
  284. [ "${Location}" == '9' ] && REGION='ap-shanghai-fsi'
  285. [ "${Location}" == '10' ] && REGION='ap-beijing-fsi'
  286. [ "${Location}" == '11' ] && REGION='ap-hongkong'
  287. [ "${Location}" == '12' ] && REGION='ap-singapore'
  288. [ "${Location}" == '13' ] && REGION='ap-mumbai'
  289. [ "${Location}" == '14' ] && REGION='ap-jakarta'
  290. [ "${Location}" == '15' ] && REGION='ap-seoul'
  291. [ "${Location}" == '16' ] && REGION='ap-bangkok'
  292. [ "${Location}" == '17' ] && REGION='ap-tokyo'
  293. [ "${Location}" == '18' ] && REGION='na-siliconvalley'
  294. [ "${Location}" == '19' ] && REGION='na-ashburn'
  295. [ "${Location}" == '20' ] && REGION='na-toronto'
  296. [ "${Location}" == '21' ] && REGION='sa-saopaulo'
  297. [ "${Location}" == '22' ] && REGION='eu-frankfurt'
  298. [ "${Location}" == '23' ] && REGION='eu-moscow'
  299. while :; do echo
  300. read -e -p "Please enter the Qcloud COS APPID: " APPID
  301. [[ ! "${APPID}" =~ ^[0-9]+$ ]] && { echo "${CWARNING}input error, must be a number${CEND}"; continue; }
  302. echo
  303. read -e -p "Please enter the Qcloud COS SECRET_ID: " SECRET_ID
  304. [ -z "${SECRET_ID}" ] && continue
  305. echo
  306. read -e -p "Please enter the Qcloud COS SECRET_KEY: " SECRET_KEY
  307. [ -z "${SECRET_KEY}" ] && continue
  308. echo
  309. read -e -p "Please enter the Qcloud COS BUCKET: " COS_BUCKET
  310. if [[ ${COS_BUCKET} =~ "-${APPID}"$ ]]; then
  311. COS_BUCKET=${COS_BUCKET}
  312. else
  313. [ -z "${COS_BUCKET}" ] && continue
  314. echo
  315. COS_BUCKET=${COS_BUCKET}-${APPID}
  316. fi
  317. ${python_install_dir}/bin/coscmd config -u ${APPID} -a ${SECRET_ID} -s ${SECRET_KEY} -r ${REGION} -b ${COS_BUCKET} > /dev/null 2>&1
  318. ${python_install_dir}/bin/coscmd list > /dev/null 2>&1
  319. if [ $? -eq 0 ]; then
  320. echo "${CMSG}APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET OK${CEND}"
  321. echo
  322. break
  323. else
  324. ${python_install_dir}/bin/coscmd -b ${COS_BUCKET} createbucket > /dev/null 2>&1
  325. if [ $? -eq 0 ]; then
  326. echo "${CMSG}Bucket ${COS_BUCKET} created${CEND}"
  327. echo
  328. break
  329. else
  330. echo "${CWARNING}input error! APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET invalid${CEND}"
  331. continue
  332. fi
  333. fi
  334. done
  335. fi
  336. if [ -n "`echo ${desc_bk} | grep -w 5`" ]; then
  337. if [ ! -e "/usr/local/bin/upx" ]; then
  338. if [ "${armplatform}" == 'y' ]; then
  339. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx_0.3.6_linux_arm64.tar.gz -O /tmp/upx_0.3.6_linux_arm64.tar.gz
  340. tar xzf /tmp/upx_0.3.6_linux_arm64.tar.gz -C /tmp/
  341. else
  342. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx_0.3.6_linux_x86_64.tar.gz -O /tmp/upx_0.3.6_linux_x86_64.tar.gz
  343. tar xzf /tmp/upx_0.3.6_linux_x86_64.tar.gz -C /tmp/
  344. fi
  345. /bin/mv /tmp/upx /usr/local/bin/upx
  346. chmod +x /usr/local/bin/upx
  347. rm -f /tmp/upx_* /tmp/LICENSE /tmp/README.md
  348. fi
  349. while :; do echo
  350. read -e -p "Please enter the upyun ServiceName: " ServiceName
  351. [ -z "${ServiceName}" ] && continue
  352. echo
  353. read -e -p "Please enter the upyun Operator: " Operator
  354. [ -z "${Operator}" ] && continue
  355. echo
  356. read -e -p "Please enter the upyun Password: " Password
  357. [ -z "${Password}" ] && continue
  358. echo
  359. /usr/local/bin/upx login ${ServiceName} ${Operator} ${Password} > /dev/null 2>&1
  360. if [ $? = 0 ]; then
  361. echo "${CMSG}ServiceName/Operator/Password OK${CEND}"
  362. echo
  363. break
  364. else
  365. echo "${CWARNING}input error! ServiceName/Operator/Password invalid${CEND}"
  366. fi
  367. done
  368. fi
  369. if [ -n "`echo ${desc_bk} | grep -w 6`" ]; then
  370. if [ ! -e "/usr/local/bin/qshell" ]; then
  371. if [ "${armplatform}" == 'y' ]; then
  372. wget -qc https://devtools.qiniu.com/qshell-v2.6.2-linux-arm64.tar.gz -O /tmp/qshell-v2.6.2-linux-arm64.tar.gz
  373. tar xzf /tmp/qshell-v2.6.2-linux-arm64.tar.gz -C /usr/local/bin/
  374. else
  375. wget -qc https://devtools.qiniu.com/qshell-v2.6.2-linux-amd64.tar.gz -O /tmp/qshell-v2.6.2-linux-amd64.tar.gz
  376. tar xzf /tmp/qshell-v2.6.2-linux-amd64.tar.gz -C /usr/local/bin/
  377. fi
  378. chmod +x /usr/local/bin/qshell
  379. rm -f /tmp/qshell*
  380. fi
  381. while :; do echo
  382. echo 'Please select your backup qiniu datacenter:'
  383. echo -e "\t ${CMSG} 1${CEND}. 华东 ${CMSG}2${CEND}. 华北"
  384. echo -e "\t ${CMSG} 3${CEND}. 华南 ${CMSG}4${CEND}. 北美"
  385. echo -e "\t ${CMSG} 5${CEND}. 东南亚 ${CMSG}6${CEND}. 华东-浙江2"
  386. read -e -p "Please input a number:(Default 1 press Enter) " Location
  387. Location=${Location:-1}
  388. if [[ "${Location}" =~ ^[1-6]$ ]]; then
  389. break
  390. else
  391. echo "${CWARNING}input error! Please only input number 1~6${CEND}"
  392. fi
  393. done
  394. [ "${Location}" == '1' ] && zone='z0'
  395. [ "${Location}" == '2' ] && zone='z1'
  396. [ "${Location}" == '3' ] && zone='z2'
  397. [ "${Location}" == '4' ] && zone='na0'
  398. [ "${Location}" == '5' ] && zone='as0'
  399. [ "${Location}" == '6' ] && zone='cn-east-2'
  400. while :; do echo
  401. read -e -p "Please enter the qiniu AccessKey: " AccessKey
  402. [ -z "${AccessKey}" ] && continue
  403. echo
  404. read -e -p "Please enter the qiniu SecretKey: " SecretKey
  405. [ -z "${SecretKey}" ] && continue
  406. echo
  407. read -e -p "Please enter the qiniu bucket: " QINIU_BUCKET
  408. [ -z "${QINIU_BUCKET}" ] && continue
  409. echo
  410. /usr/local/bin/qshell account ${AccessKey} ${SecretKey} backup
  411. if /usr/local/bin/qshell buckets | grep -w ${QINIU_BUCKET} > /dev/null 2>&1; then
  412. sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${QINIU_BUCKET}@" ./options.conf
  413. echo "${CMSG}AccessKey/SecretKey/Bucket OK${CEND}"
  414. echo
  415. break
  416. else
  417. echo "${CWARNING}input error! AccessKey/SecretKey/Bucket invalid${CEND}"
  418. fi
  419. done
  420. fi
  421. if [ -n "`echo ${desc_bk} | grep -w 7`" ]; then
  422. Install_Python
  423. [ ! -e "${python_install_dir}/bin/s3cmd" ] && ${python_install_dir}/bin/pip install s3cmd > /dev/null 2>&1
  424. while :; do echo
  425. echo 'Please select your backup amazon datacenter:'
  426. echo -e "\t ${CMSG} 1${CEND}. us-east-2 ${CMSG} 2${CEND}. us-east-1"
  427. echo -e "\t ${CMSG} 3${CEND}. us-west-1 ${CMSG} 4${CEND}. us-west-2"
  428. echo -e "\t ${CMSG} 5${CEND}. ap-south-1 ${CMSG} 6${CEND}. ap-northeast-3"
  429. echo -e "\t ${CMSG} 7${CEND}. ap-northeast-2 ${CMSG} 8${CEND}. ap-southeast-1"
  430. echo -e "\t ${CMSG} 9${CEND}. ap-southeast-2 ${CMSG}10${CEND}. ap-northeast-1"
  431. echo -e "\t ${CMSG}11${CEND}. ca-central-1 ${CMSG}12${CEND}. cn-north-1"
  432. echo -e "\t ${CMSG}13${CEND}. cn-northwest-1 ${CMSG}14${CEND}. eu-central-1"
  433. echo -e "\t ${CMSG}15${CEND}. eu-west-1 ${CMSG}16${CEND}. eu-west-2"
  434. echo -e "\t ${CMSG}17${CEND}. eu-west-3 ${CMSG}18${CEND}. eu-north-1"
  435. echo -e "\t ${CMSG}19${CEND}. sa-east-1 ${CMSG}20${CEND}. us-gov-east-1"
  436. echo -e "\t ${CMSG}21${CEND}. us-gov-west-1"
  437. read -e -p "Please input a number:(Default 1 press Enter) " Location
  438. Location=${Location:-1}
  439. if [[ "${Location}" =~ ^[1-9]$|^1[0-9]$|^2[0-1]$ ]]; then
  440. break
  441. else
  442. echo "${CWARNING}input error! Please only input number 1~21${CEND}"
  443. fi
  444. done
  445. [ "${Location}" == '1' ] && REGION='us-east-2'
  446. [ "${Location}" == '2' ] && REGION='us-east-1'
  447. [ "${Location}" == '3' ] && REGION='us-west-1'
  448. [ "${Location}" == '4' ] && REGION='us-west-2'
  449. [ "${Location}" == '5' ] && REGION='ap-south-1'
  450. [ "${Location}" == '6' ] && REGION='ap-northeast-3'
  451. [ "${Location}" == '7' ] && REGION='ap-northeast-2'
  452. [ "${Location}" == '8' ] && REGION='ap-southeast-1'
  453. [ "${Location}" == '9' ] && REGION='ap-southeast-2'
  454. [ "${Location}" == '10' ] && REGION='ap-northeast-1'
  455. [ "${Location}" == '11' ] && REGION='ca-central-1'
  456. [ "${Location}" == '12' ] && REGION='cn-north-1'
  457. [ "${Location}" == '13' ] && REGION='cn-northwest-1'
  458. [ "${Location}" == '14' ] && REGION='eu-central-1'
  459. [ "${Location}" == '15' ] && REGION='eu-west-1'
  460. [ "${Location}" == '16' ] && REGION='eu-west-2'
  461. [ "${Location}" == '17' ] && REGION='eu-west-3'
  462. [ "${Location}" == '18' ] && REGION='eu-north-1'
  463. [ "${Location}" == '19' ] && REGION='sa-east-1'
  464. [ "${Location}" == '20' ] && REGION='us-gov-east-1'
  465. [ "${Location}" == '21' ] && REGION='us-gov-west-1'
  466. while :; do echo
  467. read -e -p "Please enter the AWS Access Key: " ACCESS_KEY
  468. [ -z "${ACCESS_KEY}" ] && continue
  469. echo
  470. read -e -p "Please enter the AWS Access Key: " SECRET_KEY
  471. [ -z "${SECRET_KEY}" ] && continue
  472. ${python_install_dir}/bin/s3cmd --access_key=${ACCESS_KEY} --secret_key=${SECRET_KEY} --region=${REGION} la > /dev/null 2>&1
  473. if [ $? -eq 0 ]; then
  474. ${python_install_dir}/bin/s3cmd --configure --access_key=${ACCESS_KEY} --secret_key=${SECRET_KEY} --region=${REGION} --dump-config > ~/.s3cfg
  475. echo "${CMSG}ACCESS_KEY/SECRET_KEY OK${CEND}"
  476. while :; do echo
  477. read -e -p "Please enter the Amazon S3 bucket: " S3_BUCKET
  478. [ -z "${S3_BUCKET}" ] && continue
  479. ${python_install_dir}/bin/s3cmd ls s3://${S3_BUCKET} > /dev/null 2>&1
  480. if [ $? -eq 0 ]; then
  481. echo "${CMSG}Bucket s3://${S3_BUCKET}/ existed${CEND}"
  482. sed -i "s@^s3_bucket=.*@s3_bucket=${S3_BUCKET}@" ./options.conf
  483. break
  484. else
  485. ${python_install_dir}/bin/s3cmd mb s3://${S3_BUCKET} > /dev/null 2>&1
  486. if [ $? -eq 0 ]; then
  487. echo "${CMSG}Bucket s3://${S3_BUCKET}/ created${CEND}"
  488. sed -i "s@^s3_bucket=.*@s3_bucket=${S3_BUCKET}@" ./options.conf
  489. break
  490. else
  491. echo "${CWARNING}The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.${CEND}"
  492. continue
  493. fi
  494. fi
  495. done
  496. break
  497. else
  498. echo "${CWARNING}input error! ACCESS_KEY/SECRET_KEY invalid${CEND}"
  499. continue
  500. fi
  501. done
  502. fi
  503. if [ -n "`echo ${desc_bk} | grep -w 8`" ]; then
  504. if [ ! -e "/usr/local/bin/dbxcli" ]; then
  505. if [ "${armplatform}" == 'y' ]; then
  506. wget -qc http://mirrors.linuxeye.com/oneinstack/src/dbxcli-linux-arm -O /usr/local/bin/dbxcli
  507. else
  508. wget -qc http://mirrors.linuxeye.com/oneinstack/src/dbxcli-linux-amd64 -O /usr/local/bin/dbxcli
  509. fi
  510. chmod +x /usr/local/bin/dbxcli
  511. fi
  512. while :; do echo
  513. if dbxcli account; then
  514. break
  515. fi
  516. done
  517. fi