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.     
  182.     color_echo g "Enter the mode of adding files! Some patterns are available, as follows:"
  183.     color_echo g "eg: /home/#/tmp/ means we want to backup the whole things which "
  184.     color_echo g "are under home directory to /tmp directory."
  185.     color_echo g "eg: /home/#/tmp/:/etc/#/tmp/ means we want to backup the whole "
  186.     color_echo g "things which are under the home directory and the /etc/ directory "
  187.     color_echo g "to the /tmp directory, you can append any item with ':'."
  188.     color_echo r "Note: /home and /home/ are quite different, because /home just means "
  189.     color_echo r "/home itself while /home/ means the whole contents of /home."
  190.     read -p "Please type in file items: " items
  191.     items="`echo "$items" | sed "s/'//g"`"
  192.     flag=0
  193.     while [ $flag = 0 ]; 
  194.     do 
  195.         item=${items%%:*}
  196.         items=${items#$item:}
  197.         ex_src=""
  198.         if [ "$items" = "$item" ]; then 
  199.             flag=1
  200.         fi 
  201.         if parse_item "$item"; then
  202.             check_src_dst "$src" "$dst"
  203.             ret=$?
  204.             if [ "$ret" = 0 ]; then
  205.                 color_echo y "Warning! ""$src#$dst"" is already existed! do not re-submit!" 
  206.                 continue
  207.             elif [ "$ret" = 2 ]; then
  208.                 continue
  209.             fi
  210.             read -p "Would you like to add some excluding conditions to $src: (y/n)[n] " yn
  211.             if [ "$yn" = y ]; then
  212.                 color_echo r "Note: this is an expert mode, and we don't check your pattern"
  213.                 color_echo r "is valid or not. Some patterns are available, as follows:"
  214.                 color_echo r "eg: if your src directory is /home, and your want to exclude"
  215.                 color_echo r "the directory /home/rongp, then you should type in \"rongp\"." 
  216.                 color_echo r "eg: if your src directory is /home, and your want to exclude"
  217.                 color_echo r "the directory /home/rongp and /home/test, then you should" 
  218.                 color_echo r "type in \"rongp:test\", and you can append any item with ':' ."
  219.                 
  220.                 read -p "Please type in paths to the excluding files: " exitem 
  221.                 ex_src="$exitem"
  222.             fi
  223.             if insert_new_item "$src" "$dst" "$ex_src"; then
  224.                 echo ""$src"#"$dst" add successed!"
  225.             else 
  226.                 echo ""$src"#"$dst" add failed!"
  227.             fi
  228.         else 
  229.             read -p "skip it? Yy/Nn:[n] " yn
  230.             if [ "$yn" = "y" -o "$yn" = "Y" ]; then
  231.                 continue
  232.             fi
  233.             return 1
  234.         fi
  235.     done
  236.     return 0
  237. }
  238. get_choices()
  239. {
  240.     local total_line=`wc -l $db_pathname | cut -d ' ' -f 1`
  241.     
  242.     select_tab=
  243.     color_echo g "Enter the mode of "$1"! some patterns are available, as follows:"
  244.     color_echo g "eg: 1-3 means select no 1 2 3 item"
  245.     color_echo g "eg: 1:3:5 means select no 1 3 5 item"
  246.     color_echo g "you can append any no with ':' or '-', but don't mix use it."
  247.     color_echo g "no 0 means select all."
  248.     do_print
  249.     read -p "Please type in the number: " NO
  250.     if [ "${NO/-/ }" != "$NO" ]; then 
  251.         num_tab=(${NO//-/ })
  252.         [ ${#num_tab[@]} -gt 2 ] && \
  253.             echo "Select failed, argument $NO is illegal!" && return 1
  254.         
  255.         num0=${num_tab[0]}
  256.         num1=${num_tab[1]}
  257.         XECHO num0:$num0 num1:$num1
  258.         if [ -z "${num0//[0-9]/}" -a "$num0" -le "$total_line" -a "$num0" -gt "0" ]\
  259.            && [ -z "${num1//[0-9]/}" -a "$num1" -le "$total_line" -a "$num1" -gt "0" ]\
  260.            && [ "$num0" -lt "$num1" ]; 
  261.         then
  262.             select_tab=(`seq $num0 $num1`)
  263.         else 
  264.             echo "Select failed, argument $NO is illegal!" && return 1
  265.         fi
  266.     elif [ "${NO/:/ }" != "$NO" ]; then
  267.         for num in ${NO//:/ }
  268.         do
  269.             if [ -z "${num//[0-9]/}" ]&&[ "$num" -le "$total_line" ]\
  270.                 &&[ "$num" -gt "0" ]; then
  271.                 continue
  272.             else 
  273.                 echo "Select failed, argument $num is illegal!" && return 1
  274.             fi
  275.         done
  276.         j=0
  277.         for i in ${NO//:/ }
  278.         do
  279.             select_tab[j]=$i
  280.             ((j++))
  281.         done
  282.     else 
  283.         if [ "$NO" = 0 ]; then
  284.             select_tab=(`seq 1 $total_line`)
  285.         elif [ -z "${NO//[0-9]/}" ]&&[ "$NO" -le "$total_line" ]\
  286.                 &&[ "$NO" -gt "0" ]; then
  287.             select_tab[0]=${NO}
  288.         else 
  289.             echo "Select failed, argument $NO is illegal!" && return 1
  290.         fi
  291.     fi
  292.     return 0
  293. }
  294. do_del() 
  295. {
  296.     if ! get_choices "deleting files"; then
  297.         return 1
  298.     fi
  299.     local total_num=${#select_tab[@]}
  300.     if [ "$total_num" = 1 ]; then
  301.         nums=${select_tab[0]}d
  302.     elif [ "$total_num" = 2 ]; then
  303.         nums=${select_tab[0]},${select_tab[1]}d
  304.     else 
  305.         for ((i=0; i<$total_num; ++i))
  306.         do
  307.             nums+="${select_tab[i]}d;"
  308.         done
  309.     fi
  310.     sed -i "$nums" $db_pathname >/dev/null 2>&1
  311.     [ "$?" = 0 ] && echo "$NO delete successed!" || echo "$NO delete failed, delete failed!"
  312. }
  313. do_print()
  314. {
  315.     [ ! -s $db_pathname ] && color_echo y "Warning, no record found!" && return 1
  316.     echo " no source destination action"
  317.     cat -n $db_pathname | sed 's/@#@/ /g'
  318. }
  319. check_in_select_tab()
  320. {
  321.     local i
  322.     for ((i=0; i<${#select_tab[@]}; ++i))
  323.     do
  324.         XECHO $1:select_tab[$i]:${select_tab[i]}
  325.         if [ "${select_tab[i]}" = "$1" ]; then
  326.             return 0
  327.         fi
  328.     done
  329.     return 1
  330. }
  331. do_backup()
  332. {
  333.     local ex_file=`mktemp`
  334.     local fake="${1/fake/-n}"
  335.     local yes="${1/yes/y}"
  336.     [ ! -f "$db_pathname" ] && color_echo r "$db_pathname does not exist!" && return 1
  337.     if ! get_choices "backup"; then
  338.         return 1
  339.     fi
  340.     local i=0
  341.     local k=0
  342.     while read -r src dst ex_src;
  343.     do
  344.         if check_in_select_tab $((i+1)); then
  345.             XECHO "$i in select table"
  346.             src="${src//@#@/ }"
  347.             dst="${dst//@#@/ }"
  348.             XECHO src:$src dst:$dst ex_src:$ex_src ex_file:$ex_file
  349.             src_tab[k]="$src"
  350.             dst_tab[k]="$dst"
  351.             ex_src_tab[k]="$ex_src"
  352.             ((k++))
  353.         fi
  354.         ((i++))
  355.     done < $db_pathname
  356.     for ((j=0; j<$k; ++j))
  357.     do
  358.         echo src:${src_tab[j]} dst:${dst_tab[j]} ex_src:${ex_src_tab[j]}
  359.         src="${src_tab[j]}"
  360.         dst="${dst_tab[j]}"
  361.         ex_src="${ex_src_tab[j]}"
  362.         echo "$ex_src" | awk -F ':' '{for (i=1;i<=NF;++i)print $i}' | sed 's/@#@/ /g' > $ex_file
  363.         if [ "$src" = "/" ]; then
  364.             tmpsrc=$(blkid `mount | grep "/ " | cut -d ' ' -f 1` | awk -F "\"" '{print $2}')
  365.         else 
  366.             tmpsrc="$src"
  367.         fi
  368.         
  369.         if [ "$dst" = "/" ]; then
  370.             tmpdst=$(blkid `mount | grep "/ " | cut -d ' ' -f 1` | awk -F "\"" '{print $2}')
  371.         else 
  372.             tmpdst="$dst"
  373.         fi
  374.         color_echo g "We will start backup from "
  375.         color_echo r "$src"
  376.         color_echo g to 
  377.         color_echo r "$dst" 
  378.         color_echo g "with excluding file or directory" 
  379.         color_echo r "${ex_src//@#@/ }"
  380.         color_echo gn "continue or not? y/n: "
  381.         if [ "$yes" = y ]; then 
  382.             yn=y
  383.         else 
  384.             read yn
  385.         fi
  386.         if [ "$yn" = y ]; then
  387.             echo Start backup "$src" to "$dst" with excluding file or directory "$ex_src"
  388.             (
  389.             flock -x 200
  390.             rsync -avzrtopg $fake --progress --delete --exclude-from=$ex_file \
  391.                 "$src" "$dst" --backup --backup-dir=$inc_path/$(date +%Y-%m-%d_%H:%M:%S_$(basename ${tmpsrc})_$(basename $tmpdst))
  392.             ) 200>/var/lock/abc
  393.             echo Backup $src to $dst with excluding file or directory $ex_src 
  394.         else 
  395.             echo Skip backup $src to $dst with excluding file or directory $
  396.         fi
  397.     done
  398.     
  399. }
  400. get_answer()
  401. {
  402.     local ret
  403.     if [ "$4" != "" ]; then
  404.         tmpbackup="$4"
  405.     else
  406.         tmpbackup=backup.cfg.bak
  407.     fi
  408.     while :
  409.     do
  410.         read -p "Type in $1 path of the backup(default is $2, q for exit): " ans_tmp 
  411.         if [ "$ans_tmp" = q ]; then
  412.             ret=1
  413.             break
  414.         elif [ "$ans_tmp" != "" ]; then 
  415.             if [ ! -d "$ans_tmp" ]; then
  416.                 echo "$1: $ans_tmp is invalid!" 
  417.                 read -p "Would you like to create it now? y/n [y]: " yn
  418.                 if [ "$yn" = y ]; then
  419.                     mkdir -p $ans_tmp
  420.                 else
  421.                     continue
  422.                 fi
  423.             fi
  424.             sed -i "s,$3.*,$3$ans_tmp,g" $tmpbackup
  425.             ret=$?
  426.             break
  427.         else
  428.             ans_tmp="$2"
  429.             ret=0 
  430.             break
  431.         fi
  432.     done
  433.     return $ret
  434. }
  435. already_install()
  436. {
  437.     if load_cfg $backup_cfg s; then
  438.         XECHO "already install"
  439.         return 0 #has install
  440.     fi
  441.     return 1
  442. }
  443. do_install()
  444. { 
  445.     color_echo g start install
  446.     if already_install; then 
  447.         color_echo y "We check that you have already installed, you should"
  448.         color_echo yn "uninstall first, would you want to uninstall it first?y/n[n] "
  449.         read yn
  450.         if [ "$yn" != y ]; then
  451.             color_echo g install 
  452.             color_echo r install 
  453.             return 1
  454.         else 
  455.             do_uninstall
  456.         fi
  457.     fi
  458.     cp -f backup.cfg backup.cfg.bak
  459.     load_cfg backup.cfg.bak s
  460.     if [ "$?" = 1 ]; then
  461.         exit
  462.     fi
  463.     if ! get_answer "executable file backup" "$bin_path" "INSTALL_PATH=";then
  464.         color_echo g install 
  465.         color_echo r install 
  466.         return 1
  467.     fi
  468.     install_path=$ans_tmp
  469.     color_echo g install path is $install_path
  470.     if ! get_answer "database" "$db_path" "DB_PATH=";then
  471.         color_echo g install 
  472.         color_echo r install 
  473.         return 1
  474.     fi
  475.     db_path=$ans_tmp
  476.     color_echo g database path is $db_path
  477.     if ! get_answer "incremental backup" "$inc_path" "INCREMENTAL_BACKUP_PATH=";then
  478.         color_echo g install 
  479.         color_echo r install 
  480.         return 1
  481.     fi
  482.     inc_path=$ans_tmp
  483.     color_echo g incremental backup path is $inc_path
  484.     echo 
  485.     who=`whoami`
  486.     cp backup $install_path
  487.     color_echo g install backup to $install_path
  488.     ret=$?
  489.     mv backup.cfg.bak $backup_cfg
  490.     color_echo g install $backup_cfg
  491.     ret=$((ret+$?))
  492.     mkdir -p $db_path
  493.     color_echo g install $db_path
  494.     ret=$((ret+$?))
  495.     mkdir -p $inc_path
  496.     color_echo g install $inc_path
  497.     ret=$((ret+$?))
  498.     ln -s $db_path $inc_path/db
  499.     color_echo g install $inc_path/db
  500.     ret=$((ret+$?))
  501.     color_echo g install 
  502.     if [ $ret -gt 0 ]; then 
  503.         color_echo r install 
  504.         [ -e $bin_path/backup ] && rm_print $bin_path/backup
  505.         [ -e $backup_cfg ] && rm_print $backup_cfg
  506.         [ -e $inc_path/db ] && rm_print $inc_path/db && rm_print -rf $inc_path
  507.         [ -e $db_pathname ] && rm_print $db_pathname
  508.         rm_print -d $db_path
  509.         return 1
  510.     fi
  511.     echo 
  512.     echo 
  513.     color_echo y "The installation work is done, and you can remove this package now!"
  514.     color_echo y "Note: you should put the executable file \"backup\""
  515.     color_echo y "into \$PATH and you need to get \"root\" privileges to execute it."
  516.     color_echo y "for example, you can execute it like this in ubuntu: sudo backup"
  517.     return 0
  518. }
  519. rm_print()
  520. {
  521.     color_echo g remove $@
  522.     eval rm $@
  523. }
  524. do_uninstall()
  525. {
  526.     XECHO "Perform the un-installation."
  527.     color_echo g perform the un-installation...
  528.     if ! load_cfg $backup_cfg; then 
  529.         color_echo g uninstall 
  530.     fi
  531.     [ -e $bin_path/backup ] && rm_print $bin_path/backup
  532.     [ -e $backup_cfg ] && rm_print $backup_cfg
  533.     [ -e $inc_path/db ] && rm_print $inc_path/db && rm_print -rf $inc_path
  534.     [ -e $db_pathname ] && rm_print $db_pathname
  535.     rm_print -d $db_path
  536.     color_echo g uninstall 
  537.     color_echo g uninstall 
  538. }
  539. load_cfg()
  540. {
  541.     if [ ! -e "$1" ]; then
  542.         [ "$2" != "s" ] && color_echo r "Error, we can't find the configure file $1, exit now!"
  543.         return 1
  544.     fi
  545.     bin_path=`sed -n 's/INSTALL_PATH=\(.*\)/\1/p' $1`
  546.     db_path=`sed -n 's/DB_PATH=\(.*\)/\1/p' $1`
  547.     db_pathname=$db_path/backup.db
  548.     inc_path=`sed -n 's/INCREMENTAL_BACKUP_PATH=\(.*\)/\1/p' $1`
  549.     if [ ! -d "$inc_path" ]; then 
  550.         [ "$2" != "s" ] && color_echo r Load configuration file your should
  551.         [ "$2" != "s" ] && color_echo r check the directory $db_pathname is valid or 
  552.         return 2
  553.     fi
  554.     XECHO database path is $db_path
  555.     XECHO database file path is $db_pathname
  556.     XECHO incremental backup path is $inc_path
  557.     return 0
  558. }
  559. show_configure()
  560. {
  561.     color_echo g executable backup is in $bin_path
  562.     color_echo g database directory is in $db_path
  563.     color_echo g incremental backup directory is in $inc_path
  564. }
  565. do_modify_inc_backup_path()
  566. {
  567.     if ! get_answer "incremental backup" "$inc_path" \
  568.         "INCREMENTAL_BACKUP_PATH=" $backup_cfg;then
  569.         return 1
  570.     fi
  571.     inc_path=$ans_tmp
  572.     XECHO incremental backup is $inc_path
  573.     return 0
  574. }
  575. do_configure()
  576. {
  577.     color_echo g [1] modify incremental backup path
  578.     color_echo g [2] ...
  579.     read -p "Please type in the no which you are expecting to: " no
  580.     if [ "$no" = 1 ]; then
  581.         do_modify_inc_backup_path
  582.     else
  583.         color_echo r Unsupported 
  584.     fi
  585. }
  586. backup_start()
  587. {
  588.     if ! load_cfg $backup_cfg; then 
  589.         exit
  590.     fi
  591.     while :
  592.     do
  593.         read -p "Command (h for help): " cmd
  594.         case "$cmd" in
  595.             a)
  596.                 do_add
  597.                 ;;
  598.             d)
  599.                 do_del 
  600.                 ;;
  601.             p)
  602.                 do_print
  603.                 ;;
  604.             c)
  605.                 do_configure 
  606.                 ;;
  607.             b)
  608.                 do_backup 
  609.                 ;;
  610.             bf)
  611.                 do_backup yes 
  612.                 ;;
  613.             n)
  614.                 do_backup fake
  615.                 ;;
  616.             s)
  617.                 show_configure
  618.                 ;;
  619.             i)
  620.                 do_install
  621.                 ;;
  622.             u)
  623.                 do_uninstall
  624.                 exit
  625.                 ;;
  626.             q)
  627.                 break
  628.                 ;;
  629.             h | *)
  630.                 help 
  631.                 ;;
  632.         esac
  633.     done
  634. }
  635. username=`echo $USER`
  636. if [ "$username" != root ]; then
  637.     color_echo r "Error, you need to have \"root\" privileges to execute this program."
  638.     exit
  639. fi
  640. if [ "$1" = "-i" ]; then
  641.     if ! do_install; then
  642.         color_echo y "Sorry, We can't continue any more. Exit now!" 
  643.     fi
  644.     exit
  645. elif [ "$1" = "-u" ]; then
  646.     do_uninstall 
  647.     exit
  648. elif [ "$1" = "-h" ]; then
  649.     _help
  650.     exit
  651. fi
  652. if [ ! -e $backup_cfg ]; then 
  653.     color_echo r "$backup_cfg does not exist! "
  654.     read -p "You need to install the backup first. perform the installation? y/n?[y]: " yn 
  655.     if [ "$yn" != n ]; then
  656.         do_install
  657.     else
  658.         echo Sorry, we can\'t continue any more. Exit 
  659.     fi
  660.     exit
  661. fi
  662. 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.tpcf.cn/news/296024.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈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;国王叫你呢…