backup_setup.sh 25 KB

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