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

【作者】张昺华
【出处】http://www.cnblogs.com/sky-heaven/
【博客园】 http://www.cnblogs.com/sky-heaven/
【新浪博客】 http://blog.sina.com.cn/u/2049150530
【知乎】 http://www.zhihu.com/people/zhang-bing-hua
【我的作品---旋转倒立摆】 http://v.youku.com/v_show/id_XODM5NDAzNjQw.html?spm=a2hzp.8253869.0.0&from=y1.7-2
【我的作品---自平衡自动循迹车】 http://v.youku.com/v_show/id_XODM5MzYyNTIw.html?spm=a2hzp.8253869.0.0&from=y1.7-2
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/296024.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux 文档属于apache,Apache 安装和使用文档

Apache 安装和使用文档更新时间&#xff1a;2009年11月26日 00:34:37 作者&#xff1a;Apache安装和使用文档一、准备工作&#xff1a;1台PC机&#xff0c;安装linux操作系统 参考文档linux安装.docx2 gcc的安装 参考文档gcc的安装.zip3 apache的安装包httpd-2.0.63.tar.gz二…

在数学世界,都有这些美妙的数学公式......

全世界只有3.14 % 的人关注了爆炸吧知识什么是数学&#xff1f;华罗庚说&#xff1a;宇宙之大&#xff0c;粒子之微&#xff0c;火箭之速&#xff0c;化工之巧&#xff0c;地球之变&#xff0c;生物之谜&#xff0c;日用之繁&#xff0c;无处不用数学......回首往昔&#xff0c…

.NET 生态系统的蜕变之 .NET 6云原生

云原生的英文名是cloud native&#xff0c;native 就是土著的意思&#xff0c;也就是土著对当地的环境是非常适应的&#xff0c;在云的环境和传统的数据中心是非常不同的&#xff0c;云原生就是要用的云的技术来构建应用&#xff0c; 利用云的技术来降低种端服务的风险和提高可…

Hibernate 持久化状态、HQL语句大全(转)

Hibernate 持久化状态在Hibernate中&#xff0c;最核心的概念就是对PO的状态管理。一个PO有三种状态&#xff1a; 1、未被持久化的VO 此时就是一个内存对象VO&#xff0c;由JVM管理生命周期 2、已被持久化的PO&#xff0c;并且在Session生命周期内 此时映射数据库数据&…

如何让两个安装程序setup共享同一个component—— installing shared files(version:installshield develop8.0)...

如何让两个安装程序&#xff08;setup.exe&#xff09;&#xff0c;共享同一个component&#xff1f;  要实现的效果是&#xff0c;两个程序共享同一个dll&#xff0c;当两个程序中有一个被卸载掉时&#xff0c;这个dll仍存在&#xff0c;不随着第一个卸载而从系统中删除&…

世界十大无法科学解释灵异事件(进来发表自己看发)

1、法老咒语&#xff08;世界最大灵异事件&#xff09; 2、葡萄牙灵异事件&#xff08;在网上引起了极大的轰动&#xff09; 3、伦敦塔闹鬼&#xff08;超著名&#xff09; 4、20世纪上海滩灵异事件&#xff08;孟小冬照片灵异事件&#xff09; 5、鬼脸&#xff08;墙壁上出…

宝塔linux面板假设nextcloud,宝塔面板部署NextCloud(14.0.3)逐一解决后台安全及设置警告...

刚刚把NextCloud更新到14.0.3&#xff0c;后台又出现了一堆警告&#xff0c;也是够烦的。之前写过 宝塔面板部署NextCloud逐一解决后台安全及设置警告&#xff0c;那个是基于Nextcloud 13.x的&#xff0c;所以就再补充记录一下解决如下的警告。Use of the the built in php mai…

ASP.NET Core启动地址配置方法及优先级顺序

前言默认情况下&#xff0c;ASP.NET Core使用下列2个启动地址:http://localhost:5000 https://localhost:5001同时&#xff0c;我们也可以通过配置或代码方式修改启动地址。那么&#xff0c;这几种修改方式都是什么&#xff1f;谁最后起作用呢&#xff1f;设置方法1.applicatio…

那些喜欢少妇的男生......

1 听说你喜欢少妇&#xff1f;▼2 没错&#xff01;就是它&#xff01;▼3 你还缺男朋友吗&#xff1f;▼4 还能怎么样&#xff1f;&#xff08;via&#xff1a;臭人脸上的鼻涕&#xff09;▼5 特效还能这样玩&#xff1f;▼6 哈哈哈哈哈&#xff08;via&#xff1a;Guide&…

Openfire3.10beta版源码在eclipse上部署编译

一、源码下载 最近由于需求&#xff0c;需进行openfire的插件开发&#xff0c;于是需将openfire的源码进行部署&#xff0c;目前最新的openfire稳定版本是3.9.3&#xff0c;官方下载地址是http://www.igniterealtime.org/downloads/index.jsp&#xff0c;下载页面如图&#xff…

怎样理解Linux的文件系统

怎样理解Linux的文件系统Linux所有文件都从root开始&#xff0c;用/代表, 并且延伸到子目录。DOS/Windows有不同的分区同时目录都存于分区上。Linux则通过加载的方式把所有分区都放置在root下制定的目录里。windows下最接近于root的是c:。一句话总结&#xff1a;Windows下&…

POJ 1850 Code(组合数学)

题目链接 这个题目的组合解法&#xff0c;太巧妙了。长度为n的方案数总和为C(26,n)&#xff0c;我竟没有发现。。然后长度和字符串相等的时候的情况&#xff0c;第一位默认&#xff0c;以后默认为前一位1&#xff0c;这样才能保证递增特性。 网上还有DP解法&#xff0c;智商拙计…

(10) 需求征集 -- 权限管理

权限管理&#xff0c;都碰到过哪些需求&#xff1f;我们汇总看看&#xff0c;能汇总出多少需求来&#xff1f;将权限管理、工作流管理做到我能力的极致&#xff0c;一个人只能做好那么很少的几件事情。转载于:https://blog.51cto.com/jirigala/787926

c语言中英文的作用,C语言中英文对照.doc

C语言中英文对照一File(文件) Load 加载 F3 Pick(选择) Alt-F3New 新文件Save 存盘 F2 Write To 写文件Directory 目录Change Dir 改变目录OS Shell 暂时退出Quit 退出 Alt-x二Edit 编辑 Line n Col n Insert Indent Tab Fill Unindent * D;FILE1.CLine n 光标处在文件的第n行C…

首次公开!人教版1-9年级绝密编写:被重点中小学永久收录的数学教案和试题...

全世界只有3.14 % 的人关注了爆炸吧知识在中国的教育历史上&#xff0c;不少人都会有感慨&#xff1a;“我是读着人教版教材长大的”。&#xff08;人教版即由人民教育出版社出版。&#xff09;的确&#xff0c;由毛泽东主席亲笔题写社名的人民教育出版社&#xff0c;自1950年1…

如何通过 C# 自动捕获一个文件的变更?

咨询区 PaulB&#xff1a;请问在 C# 中如何实现当一个磁盘文件的变更&#xff0c;让我的程序马上能感知到&#xff1f;回答区 Dirk Vollmar&#xff1a;在 C# 中有一个 FileSystemWatcher 类&#xff0c;它专门用来做文件的变更感知&#xff0c;大概有如下四类通知事件&#xf…

新随笔

2012年2月27日 岁数大了&#xff0c;特别愁得慌。 转载于:https://www.cnblogs.com/laozhang/archive/2012/02/27/2369771.html

Rails 开发小贴士积累

Model (ActiveRecord) 中 Boolean 类型的属性&#xff0c;在做是否存在的校验的时候&#xff0c;不能使用 presence: true ,而是要使用 inclusion: { in: [true, false] }。否则&#xff0c;当值为 false 的时候&#xff0c;会校验失败。 ClienSideValidations 对 Boolean 类型…

安装分布式文件系统MooseFS

示意图#4种角色共有的安装步骤yum install gcc zlib zlib-devel fuse fuse-devel fuse-libs libpcap libpcap-devel net-tools useradd mfs -s /sbin/nologin cd /download/ tar xf moosefs-2.0.80.tar.gz cd moosefs-2.0.80 ./configure \ --prefix/usr/local/mfs \ --with-de…

太爽了!宅男醒来后,发现自己变成了……

全世界只有3.14 % 的人关注了爆炸吧知识小编这两天看了一本关于数学家的故事后开了一个脑洞&#xff1a;如果把那些数学大神的故事写成爽文会是什么样&#xff1f;以下内容&#xff0c;纯属娱乐和虚构。前方高能预警第一章 称王冠原来是这样的“阿基米德&#xff0c;国王叫你呢…