backup_setup.sh 20 KB

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