linux下简单的备份的脚本 2 【转】

转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26807463&id=4577034

之前写过linux下简单的备份的脚本 , 最开始一直用着, 后来觉得有必要改进下它了, 不管是从操作方式上还是工作方式上。有这样的想法是因为一次备份引起的。 我经历过磁盘损坏的痛苦, 花了1500元才勉强将数据拯救回来, 于是导致我对备份要求更加高了, 我期望尽量每周备份, 期望备份的目的地是当前系统的完整镜像,也就是说我能够从备份盘启动,且启动后
系统的操作方法以及文件和当前的一模一样,每周我只需要增量备份当前的修改的备份盘,这样就安全了很多。于是就有了下面的备份脚本(我不喜欢造*,但是在linux下没有现成的适合我的)

NOTE: 当前还没有加入自动镜像系统,所以如果想镜像系统,那么可以手动这样操作, 准备一块大于当前系统盘的移动盘,
分区,注意分区的结构尽量和系统的一模一样, 然后格式化,文件系统也尽量相同, 然后就可以备份了 备份的时候主要有些
目录需要跳过,比如sys dev proc等等,需要跳过的目录可以在backup程序了面设置!
这是脚本程序:

点击(此处)折叠或打开

  1. #!/bin/bash
  2. # This program is free software; you can redistribute it and/or
  3. # modify it under the terms of the GNU General Public License as
  4. # published by the Free Software Foundation; either version 2 of
  5. # the License, or (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # Author: rongp
  12. # email: rongpmcu#gmail.com
  13. # Date: 2014/10/26
  14. # 备份程序
  15. # 特点:
  16. # 主要支持unix类系统下, 支持符号链接
  17. # 支持增量备份
  18. # 支持网络备份(由于基于rsync, 很容易加入该功能,但暂时没加入)
  19. # 文件名支持空格 但是不能出现含有@#@的文件名
  20. # 支持备份每次的更新,方便用于人工操作失误后的修复
  21. # 支持添加规则用于剔除某些文件 格式参考rsync的PATTERN部分
  22. SHELL=/bin/bash
  23. backup_cfg_path=/etc
  24. backup_cfg=$backup_cfg_path/backup.cfg
  25. db_path=
  26. db_pathname=
  27. inc_path=
  28. XECHO=1
  29. _help()
  30. {
  31. echo -e "$0 [option]\n"\
  32. "\tOption:\n"\
  33. "\t-h show this help.\n"\
  34. "\t-i perform the installation, and you should use this option\n"\
  35. "\t before using the backup to do something else.\n"\
  36. "\t-u perform the un-installation.\n"
  37. }
  38. help()
  39. {
  40. echo -e "Command action\n"\
  41. "\th show this help.\n"\
  42. "\ta add any file that you want to backup to the database.\n"\
  43. "\td delete any file that you no longer want from the database.\n"\
  44. "\tb start backup.\n"\
  45. "\tbf assume \"yes\" as answer to all prompts and run non-interactively.\n"\
  46. "\tn perform a trial backup with no changes made.\n"\
  47. "\tp print the file record.\n"\
  48. "\tc do some configurations, such as, modifying the path to the\n"\
  49. "\t database or to the incremental backup directory.\n"\
  50. "\ts show the current configuration.\n"\
  51. "\ti perform the installation, and you should use this option\n"\
  52. "\t before using the backup to do something else.\n"\
  53. "\tu perform the un-installation.\n"\
  54. "\tq quit"
  55. }
  56. color_echo()
  57. {
  58. case "$1" in
  59. g)
  60. shift
  61. echo -e "\033[32m"$@"\033[0m"
  62. ;;
  63. gn)
  64. shift
  65. echo -e -n "\033[32m"$@"\033[0m"
  66. ;;
  67. r)
  68. shift
  69. echo -e "\033[31m"$@"\033[0m"
  70. ;;
  71. y)
  72. shift
  73. echo -e "\033[33m"$@"\033[0m"
  74. ;;
  75. yn)
  76. shift
  77. echo -e -n "\033[33m"$@"\033[0m"
  78. ;;
  79. *)
  80. shift
  81. echo $@
  82. ;;
  83. esac
  84. }
  85. XECHO()
  86. {
  87. if [ "$XECHO" = 1 ]; then
  88. echo $@
  89. fi
  90. }
  91. check_src_dst()
  92. {
  93. if ! test -e "$1" || ! test -e "$2"; then
  94. color_echo r "$1" or "$2" does not ignore
  95. return 2
  96. fi
  97. local src_part1=`df "$1" | cut -d ' ' -f 1`
  98. local src_part2=`df "$2" | cut -d ' ' -f 1`
  99. local nsrc_inode=`ls -lid "$1" | cut -d ' ' -f 1`
  100. local ndst_inode=`ls -lid "$2" | cut -d ' ' -f 1`
  101. XECHO nsrc_inode:$nsrc_inode ndst_inode:$ndst_inode
  102. if [ "$src_part1" != "$src_part2" ]; then
  103. return 1
  104. fi
  105. if [ "$nsrc_inode" = "$ndst_inode" ]; then
  106. color_echo r "$src is equivalent to $dst. ignore it!"
  107. return 2
  108. fi
  109. if [ ! -e $db_pathname ]; then
  110. return 1
  111. fi
  112. while read -r tsrc tdst tex_src;
  113. do
  114. tsrc="${tsrc//@#@/ }"
  115. tdst="${tdst//@#@/ }"
  116. tex_src="${tex_src//@#@/ }"
  117. XECHO tsrc:"$tsrc" tdst:"$tdst"
  118. osrc_inode=`ls -lid "$tsrc" | cut -d ' ' -f 1`
  119. odst_inode=`ls -lid "$tdst" | cut -d ' ' -f 1`
  120. XECHO osrc_inode:$osrc_inode odst_inode:$odst_inode
  121. if [ "$nsrc_inode" = "$osrc_inode" -a "$ndst_inode" = "$odst_inode" ]; then
  122. if [ ${1:((${#1}-1))} = '/' -a ${tsrc:((${#tsrc}-1))} != '/' ] \
  123. || [ ${1:((${#1}-1))} != '/' -a ${tsrc:((${#tsrc}-1))} = '/' ]; then #/home and /home/ is very
  124. echo -n "";
  125. else
  126. return 0
  127. fi
  128. fi
  129. done < $db_pathname
  130. return 1
  131. }
  132. extract_src_dst()
  133. {
  134. XECHO "extract src dst from $1"
  135. src="${1%#*}"
  136. dst="${1#$src}"
  137. dst="${dst#\#}"
  138. XECHO "src: $src"
  139. XECHO "dst: $dst"
  140. if [ "$src" = "" -o "$dst" = "" ]; then
  141. return 1
  142. else
  143. return 0
  144. fi
  145. }
  146. fix_path()
  147. {
  148. local srcpath="$1"
  149. if [ "${srcpath:0:1}" = '/' ]; then
  150. echo $srcpath
  151. elif [ "${srcpath:0:2}" = './' ]; then
  152. echo `pwd`/${srcpath:2}
  153. else
  154. echo `pwd`/$srcpath
  155. fi
  156. }
  157. insert_new_item()
  158. {
  159. XECHO add item src:"$1" dst:"$2" exclude:"$3"
  160. tmp1="${1// /@#@}"
  161. tmp2="${2// /@#@}"
  162. tmp3="${3// /@#@}"
  163. echo "$tmp1" "$tmp2" "$tmp3" >> $db_pathname
  164. return $?
  165. }
  166. parse_item()
  167. {
  168. if ! extract_src_dst "$1"; then
  169. color_echo r "src:$src or dst:$dst is illegal!"
  170. return 1
  171. fi
  172. src=`fix_path "$src"`
  173. dst=`fix_path "$dst"`
  174. XECHO after fixed, src:"$src"
  175. XECHO after fixed, src:"$dst"
  176. return 0
  177. }
  178. do_add()
  179. {
  180. local item
  181. color_echo g "Enter the mode of adding files! Some patterns are available, as follows:"
  182. color_echo g "eg: /home/#/tmp/ means we want to backup the whole things which "
  183. color_echo g "are under home directory to /tmp directory."
  184. color_echo g "eg: /home/#/tmp/:/etc/#/tmp/ means we want to backup the whole "
  185. color_echo g "things which are under the home directory and the /etc/ directory "
  186. color_echo g "to the /tmp directory, you can append any item with ':'."
  187. color_echo r "Note: /home and /home/ are quite different, because /home just means "
  188. color_echo r "/home itself while /home/ means the whole contents of /home."
  189. read -p "Please type in file items: " items
  190. items="`echo "$items" | sed "s/'//g"`"
  191. flag=0
  192. while [ $flag = 0 ];
  193. do
  194. item=${items%%:*}
  195. items=${items#$item:}
  196. ex_src=""
  197. if [ "$items" = "$item" ]; then
  198. flag=1
  199. fi
  200. if parse_item "$item"; then
  201. check_src_dst "$src" "$dst"
  202. ret=$?
  203. if [ "$ret" = 0 ]; then
  204. color_echo y "Warning! ""$src#$dst"" is already existed! do not re-submit!"
  205. continue
  206. elif [ "$ret" = 2 ]; then
  207. continue
  208. fi
  209. read -p "Would you like to add some excluding conditions to $src: (y/n)[n] " yn
  210. if [ "$yn" = y ]; then
  211. color_echo r "Note: this is an expert mode, and we don't check your pattern"
  212. color_echo r "is valid or not. Some patterns are available, as follows:"
  213. color_echo r "eg: if your src directory is /home, and your want to exclude"
  214. color_echo r "the directory /home/rongp, then you should type in \"rongp\"."
  215. color_echo r "eg: if your src directory is /home, and your want to exclude"
  216. color_echo r "the directory /home/rongp and /home/test, then you should"
  217. color_echo r "type in \"rongp:test\", and you can append any item with ':' ."
  218. read -p "Please type in paths to the excluding files: " exitem
  219. ex_src="$exitem"
  220. fi
  221. if insert_new_item "$src" "$dst" "$ex_src"; then
  222. echo ""$src"#"$dst" add successed!"
  223. else
  224. echo ""$src"#"$dst" add failed!"
  225. fi
  226. else
  227. read -p "skip it? Yy/Nn:[n] " yn
  228. if [ "$yn" = "y" -o "$yn" = "Y" ]; then
  229. continue
  230. fi
  231. return 1
  232. fi
  233. done
  234. return 0
  235. }
  236. get_choices()
  237. {
  238. local total_line=`wc -l $db_pathname | cut -d ' ' -f 1`
  239. select_tab=
  240. color_echo g "Enter the mode of "$1"! some patterns are available, as follows:"
  241. color_echo g "eg: 1-3 means select no 1 2 3 item"
  242. color_echo g "eg: 1:3:5 means select no 1 3 5 item"
  243. color_echo g "you can append any no with ':' or '-', but don't mix use it."
  244. color_echo g "no 0 means select all."
  245. do_print
  246. read -p "Please type in the number: " NO
  247. if [ "${NO/-/ }" != "$NO" ]; then
  248. num_tab=(${NO//-/ })
  249. [ ${#num_tab[@]} -gt 2 ] && \
  250. echo "Select failed, argument $NO is illegal!" && return 1
  251. num0=${num_tab[0]}
  252. num1=${num_tab[1]}
  253. XECHO num0:$num0 num1:$num1
  254. if [ -z "${num0//[0-9]/}" -a "$num0" -le "$total_line" -a "$num0" -gt "0" ]\
  255. && [ -z "${num1//[0-9]/}" -a "$num1" -le "$total_line" -a "$num1" -gt "0" ]\
  256. && [ "$num0" -lt "$num1" ];
  257. then
  258. select_tab=(`seq $num0 $num1`)
  259. else
  260. echo "Select failed, argument $NO is illegal!" && return 1
  261. fi
  262. elif [ "${NO/:/ }" != "$NO" ]; then
  263. for num in ${NO//:/ }
  264. do
  265. if [ -z "${num//[0-9]/}" ]&&[ "$num" -le "$total_line" ]\
  266. &&[ "$num" -gt "0" ]; then
  267. continue
  268. else
  269. echo "Select failed, argument $num is illegal!" && return 1
  270. fi
  271. done
  272. j=0
  273. for i in ${NO//:/ }
  274. do
  275. select_tab[j]=$i
  276. ((j++))
  277. done
  278. else
  279. if [ "$NO" = 0 ]; then
  280. select_tab=(`seq 1 $total_line`)
  281. elif [ -z "${NO//[0-9]/}" ]&&[ "$NO" -le "$total_line" ]\
  282. &&[ "$NO" -gt "0" ]; then
  283. select_tab[0]=${NO}
  284. else
  285. echo "Select failed, argument $NO is illegal!" && return 1
  286. fi
  287. fi
  288. return 0
  289. }
  290. do_del()
  291. {
  292. if ! get_choices "deleting files"; then
  293. return 1
  294. fi
  295. local total_num=${#select_tab[@]}
  296. if [ "$total_num" = 1 ]; then
  297. nums=${select_tab[0]}d
  298. elif [ "$total_num" = 2 ]; then
  299. nums=${select_tab[0]},${select_tab[1]}d
  300. else
  301. for ((i=0; i<$total_num; ++i))
  302. do
  303. nums+="${select_tab[i]}d;"
  304. done
  305. fi
  306. sed -i "$nums" $db_pathname >/dev/null 2>&1
  307. [ "$?" = 0 ] && echo "$NO delete successed!" || echo "$NO delete failed, delete failed!"
  308. }
  309. do_print()
  310. {
  311. [ ! -s $db_pathname ] && color_echo y "Warning, no record found!" && return 1
  312. echo " no source destination action"
  313. cat -n $db_pathname | sed 's/@#@/ /g'
  314. }
  315. check_in_select_tab()
  316. {
  317. local i
  318. for ((i=0; i<${#select_tab[@]}; ++i))
  319. do
  320. XECHO $1:select_tab[$i]:${select_tab[i]}
  321. if [ "${select_tab[i]}" = "$1" ]; then
  322. return 0
  323. fi
  324. done
  325. return 1
  326. }
  327. do_backup()
  328. {
  329. local ex_file=`mktemp`
  330. local fake="${1/fake/-n}"
  331. local yes="${1/yes/y}"
  332. [ ! -f "$db_pathname" ] && color_echo r "$db_pathname does not exist!" && return 1
  333. if ! get_choices "backup"; then
  334. return 1
  335. fi
  336. local i=0
  337. local k=0
  338. while read -r src dst ex_src;
  339. do
  340. if check_in_select_tab $((i+1)); then
  341. XECHO "$i in select table"
  342. src="${src//@#@/ }"
  343. dst="${dst//@#@/ }"
  344. XECHO src:$src dst:$dst ex_src:$ex_src ex_file:$ex_file
  345. src_tab[k]="$src"
  346. dst_tab[k]="$dst"
  347. ex_src_tab[k]="$ex_src"
  348. ((k++))
  349. fi
  350. ((i++))
  351. done < $db_pathname
  352. for ((j=0; j<$k; ++j))
  353. do
  354. echo src:${src_tab[j]} dst:${dst_tab[j]} ex_src:${ex_src_tab[j]}
  355. src="${src_tab[j]}"
  356. dst="${dst_tab[j]}"
  357. ex_src="${ex_src_tab[j]}"
  358. echo "$ex_src" | awk -F ':' '{for (i=1;i<=NF;++i)print $i}' | sed 's/@#@/ /g' > $ex_file
  359. if [ "$src" = "/" ]; then
  360. tmpsrc=$(blkid `mount | grep "/ " | cut -d ' ' -f 1` | awk -F "\"" '{print $2}')
  361. else
  362. tmpsrc="$src"
  363. fi
  364. if [ "$dst" = "/" ]; then
  365. tmpdst=$(blkid `mount | grep "/ " | cut -d ' ' -f 1` | awk -F "\"" '{print $2}')
  366. else
  367. tmpdst="$dst"
  368. fi
  369. color_echo g "We will start backup from "
  370. color_echo r "$src"
  371. color_echo g to
  372. color_echo r "$dst"
  373. color_echo g "with excluding file or directory"
  374. color_echo r "${ex_src//@#@/ }"
  375. color_echo gn "continue or not? y/n: "
  376. if [ "$yes" = y ]; then
  377. yn=y
  378. else
  379. read yn
  380. fi
  381. if [ "$yn" = y ]; then
  382. echo Start backup "$src" to "$dst" with excluding file or directory "$ex_src"
  383. (
  384. flock -x 200
  385. rsync -avzrtopg $fake --progress --delete --exclude-from=$ex_file \
  386. "$src" "$dst" --backup --backup-dir=$inc_path/$(date +%Y-%m-%d_%H:%M:%S_$(basename ${tmpsrc})_$(basename $tmpdst))
  387. ) 200>/var/lock/abc
  388. echo Backup $src to $dst with excluding file or directory $ex_src
  389. else
  390. echo Skip backup $src to $dst with excluding file or directory $
  391. fi
  392. done
  393. }
  394. get_answer()
  395. {
  396. local ret
  397. if [ "$4" != "" ]; then
  398. tmpbackup="$4"
  399. else
  400. tmpbackup=backup.cfg.bak
  401. fi
  402. while :
  403. do
  404. read -p "Type in $1 path of the backup(default is $2, q for exit): " ans_tmp
  405. if [ "$ans_tmp" = q ]; then
  406. ret=1
  407. break
  408. elif [ "$ans_tmp" != "" ]; then
  409. if [ ! -d "$ans_tmp" ]; then
  410. echo "$1: $ans_tmp is invalid!"
  411. read -p "Would you like to create it now? y/n [y]: " yn
  412. if [ "$yn" = y ]; then
  413. mkdir -p $ans_tmp
  414. else
  415. continue
  416. fi
  417. fi
  418. sed -i "s,$3.*,$3$ans_tmp,g" $tmpbackup
  419. ret=$?
  420. break
  421. else
  422. ans_tmp="$2"
  423. ret=0
  424. break
  425. fi
  426. done
  427. return $ret
  428. }
  429. already_install()
  430. {
  431. if load_cfg $backup_cfg s; then
  432. XECHO "already install"
  433. return 0 #has install
  434. fi
  435. return 1
  436. }
  437. do_install()
  438. {
  439. color_echo g start install
  440. if already_install; then
  441. color_echo y "We check that you have already installed, you should"
  442. color_echo yn "uninstall first, would you want to uninstall it first?y/n[n] "
  443. read yn
  444. if [ "$yn" != y ]; then
  445. color_echo g install
  446. color_echo r install
  447. return 1
  448. else
  449. do_uninstall
  450. fi
  451. fi
  452. cp -f backup.cfg backup.cfg.bak
  453. load_cfg backup.cfg.bak s
  454. if [ "$?" = 1 ]; then
  455. exit
  456. fi
  457. if ! get_answer "executable file backup" "$bin_path" "INSTALL_PATH=";then
  458. color_echo g install
  459. color_echo r install
  460. return 1
  461. fi
  462. install_path=$ans_tmp
  463. color_echo g install path is $install_path
  464. if ! get_answer "database" "$db_path" "DB_PATH=";then
  465. color_echo g install
  466. color_echo r install
  467. return 1
  468. fi
  469. db_path=$ans_tmp
  470. color_echo g database path is $db_path
  471. if ! get_answer "incremental backup" "$inc_path" "INCREMENTAL_BACKUP_PATH=";then
  472. color_echo g install
  473. color_echo r install
  474. return 1
  475. fi
  476. inc_path=$ans_tmp
  477. color_echo g incremental backup path is $inc_path
  478. echo
  479. who=`whoami`
  480. cp backup $install_path
  481. color_echo g install backup to $install_path
  482. ret=$?
  483. mv backup.cfg.bak $backup_cfg
  484. color_echo g install $backup_cfg
  485. ret=$((ret+$?))
  486. mkdir -p $db_path
  487. color_echo g install $db_path
  488. ret=$((ret+$?))
  489. mkdir -p $inc_path
  490. color_echo g install $inc_path
  491. ret=$((ret+$?))
  492. ln -s $db_path $inc_path/db
  493. color_echo g install $inc_path/db
  494. ret=$((ret+$?))
  495. color_echo g install
  496. if [ $ret -gt 0 ]; then
  497. color_echo r install
  498. [ -e $bin_path/backup ] && rm_print $bin_path/backup
  499. [ -e $backup_cfg ] && rm_print $backup_cfg
  500. [ -e $inc_path/db ] && rm_print $inc_path/db && rm_print -rf $inc_path
  501. [ -e $db_pathname ] && rm_print $db_pathname
  502. rm_print -d $db_path
  503. return 1
  504. fi
  505. echo
  506. echo
  507. color_echo y "The installation work is done, and you can remove this package now!"
  508. color_echo y "Note: you should put the executable file \"backup\""
  509. color_echo y "into \$PATH and you need to get \"root\" privileges to execute it."
  510. color_echo y "for example, you can execute it like this in ubuntu: sudo backup"
  511. return 0
  512. }
  513. rm_print()
  514. {
  515. color_echo g remove $@
  516. eval rm $@
  517. }
  518. do_uninstall()
  519. {
  520. XECHO "Perform the un-installation."
  521. color_echo g perform the un-installation...
  522. if ! load_cfg $backup_cfg; then
  523. color_echo g uninstall
  524. fi
  525. [ -e $bin_path/backup ] && rm_print $bin_path/backup
  526. [ -e $backup_cfg ] && rm_print $backup_cfg
  527. [ -e $inc_path/db ] && rm_print $inc_path/db && rm_print -rf $inc_path
  528. [ -e $db_pathname ] && rm_print $db_pathname
  529. rm_print -d $db_path
  530. color_echo g uninstall
  531. color_echo g uninstall
  532. }
  533. load_cfg()
  534. {
  535. if [ ! -e "$1" ]; then
  536. [ "$2" != "s" ] && color_echo r "Error, we can't find the configure file $1, exit now!"
  537. return 1
  538. fi
  539. bin_path=`sed -n 's/INSTALL_PATH=\(.*\)/\1/p' $1`
  540. db_path=`sed -n 's/DB_PATH=\(.*\)/\1/p' $1`
  541. db_pathname=$db_path/backup.db
  542. inc_path=`sed -n 's/INCREMENTAL_BACKUP_PATH=\(.*\)/\1/p' $1`
  543. if [ ! -d "$inc_path" ]; then
  544. [ "$2" != "s" ] && color_echo r Load configuration file your should
  545. [ "$2" != "s" ] && color_echo r check the directory $db_pathname is valid or
  546. return 2
  547. fi
  548. XECHO database path is $db_path
  549. XECHO database file path is $db_pathname
  550. XECHO incremental backup path is $inc_path
  551. return 0
  552. }
  553. show_configure()
  554. {
  555. color_echo g executable backup is in $bin_path
  556. color_echo g database directory is in $db_path
  557. color_echo g incremental backup directory is in $inc_path
  558. }
  559. do_modify_inc_backup_path()
  560. {
  561. if ! get_answer "incremental backup" "$inc_path" \
  562. "INCREMENTAL_BACKUP_PATH=" $backup_cfg;then
  563. return 1
  564. fi
  565. inc_path=$ans_tmp
  566. XECHO incremental backup is $inc_path
  567. return 0
  568. }
  569. do_configure()
  570. {
  571. color_echo g [1] modify incremental backup path
  572. color_echo g [2] ...
  573. read -p "Please type in the no which you are expecting to: " no
  574. if [ "$no" = 1 ]; then
  575. do_modify_inc_backup_path
  576. else
  577. color_echo r Unsupported
  578. fi
  579. }
  580. backup_start()
  581. {
  582. if ! load_cfg $backup_cfg; then
  583. exit
  584. fi
  585. while :
  586. do
  587. read -p "Command (h for help): " cmd
  588. case "$cmd" in
  589. a)
  590. do_add
  591. ;;
  592. d)
  593. do_del
  594. ;;
  595. p)
  596. do_print
  597. ;;
  598. c)
  599. do_configure
  600. ;;
  601. b)
  602. do_backup
  603. ;;
  604. bf)
  605. do_backup yes
  606. ;;
  607. n)
  608. do_backup fake
  609. ;;
  610. s)
  611. show_configure
  612. ;;
  613. i)
  614. do_install
  615. ;;
  616. u)
  617. do_uninstall
  618. exit
  619. ;;
  620. q)
  621. break
  622. ;;
  623. h | *)
  624. help
  625. ;;
  626. esac
  627. done
  628. }
  629. username=`echo $USER`
  630. if [ "$username" != root ]; then
  631. color_echo r "Error, you need to have \"root\" privileges to execute this program."
  632. exit
  633. fi
  634. if [ "$1" = "-i" ]; then
  635. if ! do_install; then
  636. color_echo y "Sorry, We can't continue any more. Exit now!"
  637. fi
  638. exit
  639. elif [ "$1" = "-u" ]; then
  640. do_uninstall
  641. exit
  642. elif [ "$1" = "-h" ]; then
  643. _help
  644. exit
  645. fi
  646. if [ ! -e $backup_cfg ]; then
  647. color_echo r "$backup_cfg does not exist! "
  648. read -p "You need to install the backup first. perform the installation? y/n?[y]: " yn
  649. if [ "$yn" != n ]; then
  650. do_install
  651. else
  652. echo Sorry, we can\'t continue any more. Exit
  653. fi
  654. exit
  655. fi
  656. backup_start

这是配置文件

点击(此处)折叠或打开

  1. #############################
  2. ######
  3. #############################
  4. AUTHOR=rongp
  5. EMAIL=rongpmcu@gmail.com
  6. VERSION=1.0
  7. INSTALL_PATH=/usr/bin/
  8. DB_PATH=/var/lib/backup/
  9. INCREMENTAL_BACKUP_PATH=/var/lib/backup/incr_backup

git路径:git@bitbucket.org:rongpmcu/backup-script-shell.git

上一篇:SqlSever大数据分页


下一篇:linux(3)磁盘与文件系统管理/查看硬盘、内存空间/文件系统的操作/ 文件的压缩和打包