backup_setup.sh 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 8+ 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 8+ 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. wget -qc https://gosspublic.alicdn.com/ossutil/1.7.1/ossutil${OS_BIT} -O /usr/local/bin/ossutil
  173. chmod +x /usr/local/bin/ossutil
  174. fi
  175. while :; do echo
  176. echo 'Please select your backup aliyun datacenter:'
  177. echo -e "\t ${CMSG}1${CEND}. cn-hangzhou-华东 1 (杭州) ${CMSG}2${CEND}. cn-shanghai-华东 2 (上海)"
  178. echo -e "\t ${CMSG}3${CEND}. cn-qingdao-华北 1 (青岛) ${CMSG}4${CEND}. cn-beijing-华北 2 (北京)"
  179. echo -e "\t ${CMSG}5${CEND}. cn-zhangjiakou-华北 3 (张家口) ${CMSG}6${CEND}. cn-huhehaote-华北 5(呼和浩特)"
  180. echo -e "\t ${CMSG}7${CEND}. cn-shenzhen-华南 1 (深圳) ${CMSG}8${CEND}. cn-chengdu-西南 1(成都)"
  181. echo -e "\t ${CMSG}9${CEND}. cn-hongkong-香港 ${CMSG}10${CEND}. us-west-美西 1 (硅谷)"
  182. echo -e "\t${CMSG}11${CEND}. us-east-美东 1 (弗吉尼亚) ${CMSG}12${CEND}. ap-southeast-亚太东南 1 (新加坡)"
  183. echo -e "\t${CMSG}13${CEND}. ap-southeast-亚太东南 2 (悉尼) ${CMSG}14${CEND}. ap-southeast-亚太东南 3 (吉隆坡)"
  184. echo -e "\t${CMSG}15${CEND}. ap-southeast-亚太东南 5 (雅加达) ${CMSG}16${CEND}. ap-northeast-亚太东北 1 (日本)"
  185. echo -e "\t${CMSG}17${CEND}. ap-south-亚太南部 1 (孟买) ${CMSG}18${CEND}. eu-central-欧洲中部 1 (法兰克福)"
  186. echo -e "\t${CMSG}19${CEND}. eu-west-英国(伦敦) ${CMSG}20${CEND}. me-east-中东东部 1 (迪拜)"
  187. read -e -p "Please input a number:(Default 1 press Enter) " Location
  188. Location=${Location:-1}
  189. if [[ "${Location}" =~ ^[1-9]$|^1[0-9]$|^20$ ]]; then
  190. break
  191. else
  192. echo "${CWARNING}input error! Please only input number 1~20${CEND}"
  193. fi
  194. done
  195. [ "${Location}" == '1' ] && Host=oss-cn-hangzhou-internal.aliyuncs.com
  196. [ "${Location}" == '2' ] && Host=oss-cn-shanghai-internal.aliyuncs.com
  197. [ "${Location}" == '3' ] && Host=oss-cn-qingdao-internal.aliyuncs.com
  198. [ "${Location}" == '4' ] && Host=oss-cn-beijing-internal.aliyuncs.com
  199. [ "${Location}" == '5' ] && Host=oss-cn-zhangjiakou-internal.aliyuncs.com
  200. [ "${Location}" == '6' ] && Host=oss-cn-huhehaote-internal.aliyuncs.com
  201. [ "${Location}" == '7' ] && Host=oss-cn-shenzhen-internal.aliyuncs.com
  202. [ "${Location}" == '8' ] && Host=oss-cn-chengdu-internal.aliyuncs.com
  203. [ "${Location}" == '9' ] && Host=oss-cn-hongkong-internal.aliyuncs.com
  204. [ "${Location}" == '10' ] && Host=oss-us-west-1-internal.aliyuncs.com
  205. [ "${Location}" == '11' ] && Host=oss-us-east-1-internal.aliyuncs.com
  206. [ "${Location}" == '12' ] && Host=oss-ap-southeast-1-internal.aliyuncs.com
  207. [ "${Location}" == '13' ] && Host=oss-ap-southeast-2-internal.aliyuncs.com
  208. [ "${Location}" == '14' ] && Host=oss-ap-southeast-3-internal.aliyuncs.com
  209. [ "${Location}" == '15' ] && Host=oss-ap-southeast-5-internal.aliyuncs.com
  210. [ "${Location}" == '16' ] && Host=oss-ap-northeast-1-internal.aliyuncs.com
  211. [ "${Location}" == '17' ] && Host=oss-ap-south-1-internal.aliyuncs.com
  212. [ "${Location}" == '18' ] && Host=oss-eu-central-1-internal.aliyuncs.com
  213. [ "${Location}" == '19' ] && Host=oss-eu-west-1-internal.aliyuncs.com
  214. [ "${Location}" == '20' ] && Host=oss-me-east-1-internal.aliyuncs.com
  215. [ "$(./include/check_port.py ${Host} 80)" == "False" ] && Host=`echo ${Host} | sed 's@-internal@@g'`
  216. [ -e "/root/.ossutilconfig" ] && rm -f /root/.ossutilconfig
  217. while :; do echo
  218. read -e -p "Please enter the aliyun oss Access Key ID: " KeyID
  219. [ -z "${KeyID}" ] && continue
  220. echo
  221. read -e -p "Please enter the aliyun oss Access Key Secret: " KeySecret
  222. [ -z "${KeySecret}" ] && continue
  223. /usr/local/bin/ossutil ls -e ${Host} -i ${KeyID} -k ${KeySecret} > /dev/null 2>&1
  224. if [ $? -eq 0 ]; then
  225. /usr/local/bin/ossutil config -e ${Host} -i ${KeyID} -k ${KeySecret} > /dev/null 2>&1
  226. while :; do echo
  227. read -e -p "Please enter the aliyun oss bucket: " OSS_BUCKET
  228. /usr/local/bin/ossutil mb oss://${OSS_BUCKET} > /dev/null 2>&1
  229. if [ $? -eq 0 ]; then
  230. echo "${CMSG}Bucket oss://${OSS_BUCKET}/ created${CEND}"
  231. sed -i "s@^oss_bucket=.*@oss_bucket=${OSS_BUCKET}@" ./options.conf
  232. break
  233. else
  234. echo "${CWARNING}[${OSS_BUCKET}] already exists, You need to use the OSS Console to create a bucket for storing.${CEND}"
  235. fi
  236. done
  237. break
  238. fi
  239. done
  240. fi
  241. if [ -n "`echo ${desc_bk} | grep -w 4`" ]; then
  242. Install_Python
  243. [ ! -e "${python_install_dir}/bin/coscmd" ] && ${python_install_dir}/bin/pip install coscmd > /dev/null 2>&1
  244. while :; do echo
  245. echo 'Please select your backup qcloud datacenter:'
  246. echo -e "\t ${CMSG} 1${CEND}. ap-beijing-1-北京一区(华北) ${CMSG}2${CEND}. ap-beijing-北京"
  247. echo -e "\t ${CMSG} 3${CEND}. ap-shanghai-上海(华东) ${CMSG}4${CEND}. ap-guangzhou-广州(华南)"
  248. echo -e "\t ${CMSG} 5${CEND}. ap-chengdu-成都(西南) ${CMSG}6${CEND}. ap-chongqing-重庆"
  249. echo -e "\t ${CMSG} 7${CEND}. ap-shenzhen-fsi-深圳金融 ${CMSG}8${CEND}. ap-shanghai-fsi-上海金融"
  250. echo -e "\t ${CMSG} 9${CEND}. ap-beijing-fsi-北京金融 ${CMSG}10${CEND}. ap-hongkong-香港"
  251. echo -e "\t ${CMSG}11${CEND}. ap-singapore-新加坡 ${CMSG}12${CEND}. ap-mumbai-孟买"
  252. echo -e "\t ${CMSG}13${CEND}. ap-seoul-首尔 ${CMSG}14${CEND}. ap-bangkok-曼谷"
  253. echo -e "\t ${CMSG}15${CEND}. ap-tokyo-东京 ${CMSG}16${CEND}. na-siliconvalley-硅谷"
  254. echo -e "\t ${CMSG}17${CEND}. na-ashburn-弗吉尼亚 ${CMSG}18${CEND}. na-toronto-多伦多"
  255. echo -e "\t ${CMSG}19${CEND}. eu-frankfurt-法兰克福 ${CMSG}20${CEND}. eu-moscow-莫斯科"
  256. read -e -p "Please input a number:(Default 1 press Enter) " Location
  257. Location=${Location:-1}
  258. if [[ "${Location}" =~ ^[1-9]$|^1[0-9]$|^20$ ]]; then
  259. break
  260. else
  261. echo "${CWARNING}input error! Please only input number 1~17${CEND}"
  262. fi
  263. done
  264. [ "${Location}" == '1' ] && REGION='ap-beijing-1'
  265. [ "${Location}" == '2' ] && REGION='ap-beijing'
  266. [ "${Location}" == '3' ] && REGION='ap-shanghai'
  267. [ "${Location}" == '4' ] && REGION='ap-guangzhou'
  268. [ "${Location}" == '5' ] && REGION='ap-chengdu'
  269. [ "${Location}" == '6' ] && REGION='ap-chongqing'
  270. [ "${Location}" == '7' ] && REGION='ap-shenzhen-fsi'
  271. [ "${Location}" == '8' ] && REGION='ap-shanghai-fsi'
  272. [ "${Location}" == '9' ] && REGION='ap-beijing-fsi'
  273. [ "${Location}" == '10' ] && REGION='ap-hongkong'
  274. [ "${Location}" == '11' ] && REGION='ap-singapore'
  275. [ "${Location}" == '12' ] && REGION='ap-mumbai'
  276. [ "${Location}" == '13' ] && REGION='ap-seoul'
  277. [ "${Location}" == '14' ] && REGION='ap-bangkok'
  278. [ "${Location}" == '15' ] && REGION='ap-tokyo'
  279. [ "${Location}" == '16' ] && REGION='na-siliconvalley'
  280. [ "${Location}" == '17' ] && REGION='na-ashburn'
  281. [ "${Location}" == '18' ] && REGION='na-toronto'
  282. [ "${Location}" == '19' ] && REGION='eu-frankfurt'
  283. [ "${Location}" == '20' ] && REGION='eu-moscow'
  284. while :; do echo
  285. read -e -p "Please enter the Qcloud COS APPID: " APPID
  286. [[ ! "${APPID}" =~ ^[0-9]+$ ]] && { echo "${CWARNING}input error, must be a number${CEND}"; continue; }
  287. echo
  288. read -e -p "Please enter the Qcloud COS SECRET_ID: " SECRET_ID
  289. [ -z "${SECRET_ID}" ] && continue
  290. echo
  291. read -e -p "Please enter the Qcloud COS SECRET_KEY: " SECRET_KEY
  292. [ -z "${SECRET_KEY}" ] && continue
  293. echo
  294. read -e -p "Please enter the Qcloud COS BUCKET: " COS_BUCKET
  295. if [[ ${COS_BUCKET} =~ "-${APPID}"$ ]]; then
  296. COS_BUCKET=${COS_BUCKET}
  297. else
  298. [ -z "${COS_BUCKET}" ] && continue
  299. echo
  300. COS_BUCKET=${COS_BUCKET}-${APPID}
  301. fi
  302. ${python_install_dir}/bin/coscmd config -u ${APPID} -a ${SECRET_ID} -s ${SECRET_KEY} -r ${REGION} -b ${COS_BUCKET} > /dev/null 2>&1
  303. ${python_install_dir}/bin/coscmd list > /dev/null 2>&1
  304. if [ $? -eq 0 ]; then
  305. echo "${CMSG}APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET OK${CEND}"
  306. echo
  307. break
  308. else
  309. ${python_install_dir}/bin/coscmd -b ${COS_BUCKET} createbucket > /dev/null 2>&1
  310. if [ $? -eq 0 ]; then
  311. echo "${CMSG}Bucket ${COS_BUCKET} created${CEND}"
  312. echo
  313. break
  314. else
  315. echo "${CWARNING}input error! APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET invalid${CEND}"
  316. continue
  317. fi
  318. fi
  319. done
  320. fi
  321. if [ -n "`echo ${desc_bk} | grep -w 5`" ]; then
  322. if [ ! -e "/usr/local/bin/upx" ]; then
  323. if [ "${OS_BIT}" == '64' ]; then
  324. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx_0.3.5_linux_x86_64.tar.gz -O /tmp/upx_0.3.5_linux_x86_64.tar.gz
  325. tar xzf /tmp/upx_0.3.5_linux_x86_64.tar.gz -C /tmp/
  326. elif [ "${OS_BIT}" == '32' ]; then
  327. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx_0.3.5_linux_i386.tar.gz -O /tmp/upx_0.3.5_linux_i386.tar.gz
  328. tar xzf /tmp/upx_0.3.5_linux_i386.tar.gz -C /tmp/
  329. fi
  330. /bin/mv /tmp/upx /usr/local/bin/upx
  331. chmod +x /usr/local/bin/upx
  332. rm -f /tmp/upx_* /tmp/LICENSE /tmp/README.md
  333. fi
  334. while :; do echo
  335. read -e -p "Please enter the upyun ServiceName: " ServiceName
  336. [ -z "${ServiceName}" ] && continue
  337. echo
  338. read -e -p "Please enter the upyun Operator: " Operator
  339. [ -z "${Operator}" ] && continue
  340. echo
  341. read -e -p "Please enter the upyun Password: " Password
  342. [ -z "${Password}" ] && continue
  343. echo
  344. /usr/local/bin/upx login ${ServiceName} ${Operator} ${Password} > /dev/null 2>&1
  345. if [ $? = 0 ]; then
  346. echo "${CMSG}ServiceName/Operator/Password OK${CEND}"
  347. echo
  348. break
  349. else
  350. echo "${CWARNING}input error! ServiceName/Operator/Password invalid${CEND}"
  351. fi
  352. done
  353. fi
  354. if [ -n "`echo ${desc_bk} | grep -w 6`" ]; then
  355. if [ ! -e "/usr/local/bin/qrsctl" ]; then
  356. if [ "${OS_BIT}" == '64' ]; then
  357. wget -qc http://devtools.qiniu.com/linux/amd64/qrsctl -O /usr/local/bin/qrsctl
  358. elif [ "${OS_BIT}" == '32' ]; then
  359. wget -qc http://devtools.qiniu.com/linux/386/qrsctl -O /usr/local/bin/qrsctl
  360. fi
  361. chmod +x /usr/local/bin/qrsctl
  362. fi
  363. if [ ! -e "/usr/local/bin/qshell" ]; then
  364. if [ "${OS_BIT}" == '64' ]; then
  365. wget -qc https://devtools.qiniu.com/qshell-v2.5.0-linux-amd64.tar.gz -O /tmp/qshell-v2.5.0-linux-amd64.tar.gz
  366. tar xzf /tmp/qshell-v2.5.0-linux-amd64.tar.gz -C /usr/local/bin/
  367. elif [ "${OS_BIT}" == '32' ]; then
  368. wget -qc https://devtools.qiniu.com/qshell-v2.5.0-linux-386.tar.gz -O /tmp/qshell-v2.5.0-linux-386.tar.gz
  369. tar xzf /tmp/qshell-v2.5.0-linux-386.tar.gz -C /usr/local/bin/
  370. fi
  371. chmod +x /usr/local/bin/qshell
  372. rm -f /tmp/qshell*
  373. fi
  374. while :; do echo
  375. echo 'Please select your backup qiniu datacenter:'
  376. echo -e "\t ${CMSG} 1${CEND}. 华东 ${CMSG}2${CEND}. 华北"
  377. echo -e "\t ${CMSG} 3${CEND}. 华南 ${CMSG}4${CEND}. 北美"
  378. echo -e "\t ${CMSG} 5${CEND}. 东南亚"
  379. read -e -p "Please input a number:(Default 1 press Enter) " Location
  380. Location=${Location:-1}
  381. if [[ "${Location}" =~ ^[1-5]$ ]]; then
  382. break
  383. else
  384. echo "${CWARNING}input error! Please only input number 1~5${CEND}"
  385. fi
  386. done
  387. [ "${Location}" == '1' ] && zone='z0'
  388. [ "${Location}" == '2' ] && zone='z1'
  389. [ "${Location}" == '3' ] && zone='z2'
  390. [ "${Location}" == '4' ] && zone='na0'
  391. [ "${Location}" == '5' ] && zone='as0'
  392. while :; do echo
  393. read -e -p "Please enter the qiniu AccessKey: " AccessKey
  394. [ -z "${AccessKey}" ] && continue
  395. echo
  396. read -e -p "Please enter the qiniu SecretKey: " SecretKey
  397. [ -z "${SecretKey}" ] && continue
  398. echo
  399. read -e -p "Please enter the qiniu bucket: " QINIU_BUCKET
  400. [ -z "${QINIU_BUCKET}" ] && continue
  401. echo
  402. /usr/local/bin/qshell account ${AccessKey} ${SecretKey} backup
  403. /usr/local/bin/qrsctl login ${AccessKey} ${SecretKey}
  404. if /usr/local/bin/qrsctl bucketinfo ${QINIU_BUCKET} > /dev/null 2>&1; then
  405. sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${QINIU_BUCKET}@" ./options.conf
  406. echo "${CMSG}AccessKey/SecretKey OK${CEND}"
  407. echo
  408. break
  409. elif /usr/local/bin/qrsctl mkbucket ${QINIU_BUCKET} ${zone} > /dev/null 2>&1; then
  410. /usr/local/bin/qrsctl private ${QINIU_BUCKET} 1
  411. echo "${CMSG}Bucket ${QINIU_BUCKET} created${CEND}"
  412. sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${QINIU_BUCKET}@" ./options.conf
  413. echo "${CMSG}AccessKey/SecretKey OK${CEND}"
  414. echo
  415. break
  416. else
  417. echo "${CWARNING}input error! AccessKey/SecretKey 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 [ "${OS_BIT}" == '64' ]; then
  506. wget -qc http://mirrors.linuxeye.com/oneinstack/src/dbxcli-linux-amd64 -O /usr/local/bin/dbxcli
  507. fi
  508. chmod +x /usr/local/bin/dbxcli
  509. fi
  510. while :; do echo
  511. if dbxcli account; then
  512. break
  513. fi
  514. done
  515. fi