Chinaunix首页 | 论坛 | 博客
  • 博客访问: 268744
  • 博文数量: 45
  • 博客积分: 930
  • 博客等级: 准尉
  • 技术积分: 553
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-22 17:53
文章分类

全部博文(45)

文章存档

2013年(5)

2012年(40)

分类: LINUX

2012-08-09 17:57:28

backup_run.sh

点击(此处)折叠或打开

  1. #!/bin/sh
  2. # backup_run

  3. # script to run the backups
  4. # loads in a setting file for the user to change

  5. SOURCE=/home/bob/backup.defaults
  6. check_source()
  7. {
  8.     # check_source
  9.     # can we load the file
  10.     # backup.defaults is the source file containing config/functions
  11.     # make sure your path includes this directory you are runing from
  12.     if [ -r $SOURCE ];then
  13.       . $SOURCE # load $source
  14.     else
  15.         echo "`basename $0`: cannot locate default file"
  16.         exit 1
  17.     fi
  18. }

  19. header()
  20. {
  21.     # header
  22.     USER=`whoami`
  23.     MYDATE=`date +%A" "%e" of "%B-%Y`
  24.     clear
  25.     cat << HH
  26.     User: $USER $MYDATE
  27.                 NETWORK SYSTEM BACKUP
  28.                 =====================
  29. HH
  30. }

  31. change_settings()
  32. {
  33.     # change_settings
  34.     # let the user see the default settings..
  35.     header
  36.     echo "Valid Entries Are..."
  37.     echo "Tape Device: rmt0,rmt1,rmt3"
  38.     echo "Mail Admin:yes,no"
  39.     echo "Backup Type: full,normal,sybase "
  40.     while :
  41.     do
  42.         echo -n -c "\n\n Tape Device To Be Used For This Backup [$_DEVICE] :"
  43.         read T_DEVICE
  44.         : ${T_DEVICE:=$_DEVICE}
  45.         case $T_DEVICE in
  46.             rmt0|rmt1|rmt3) break
  47.                 ;;
  48.             *) echo "The device are either...rmt0,rmt1,rmt3"
  49.                 ;;
  50.         esac
  51.     done

  52.     # if the user hits return on any of the fields, the default value will be used
  53.     while :
  54.     do
  55.         echo -n "Mail Admin When Done [$_INFORM] : "
  56.         read T_INFORM
  57.         : ${T_INFORM:=$_INFORM}
  58.         case $T_INFORM in
  59.             yes|Yes) break
  60.                 ;;
  61.             no|No) break
  62.                 ;;
  63.             *) echo "The choices are yes,no"
  64.                 ;;
  65.         esac
  66.     done

  67.     while :
  68.     do
  69.         echo -n "Backup Type [$_TYPE] :"
  70.         read T_TYPE
  71.         : ${T_TYPE:=$_TYPE}
  72.         case $T_TYPE in
  73.             Full|full) break
  74.                 ;;
  75.             Normal|normal) break
  76.                 ;;
  77.             Sybase|sybase) break
  78.                 ;;
  79.             *) echo "The choices are either ... full,normal,sybase"
  80.         esac
  81.     done

  82.     # re-assign the temp varialbes back to original variables that
  83.     # were loaded in
  84.     _DEVICE=$T_DEVICE;_INFORM=$T_INFORM;_TYPE=$T_TYPE
  85. }

  86. show_settings()
  87. {
  88.     # display current settings
  89.     cat << HH
  90.                 Default Settings Are...
  91.             Tape Device To Be Used : $_DEVICE
  92.             Mail Admin When Done : $_INFORM
  93.             Type Of Backup : $_TYPE
  94.             Log File Of Backup : $_LOGFILE
  95. HH

  96. }

  97. get_code()
  98. {
  99.     # users get 3 attempts at entering the correct code
  100.     # _CODE is loaded in from the source file
  101.     clear
  102.     header
  103.     _COUNTER=0
  104.     echo "YOU MUST ENTER THE CORRECT CODE TO BE ABLE TO CHANGE DEFAULT SETTINGS"
  105.     while :
  106.     do
  107.         _COUNTER=`expr $_COUNTER + 1`
  108.         echo -n "Enter the code to change the settings: "
  109.         read T_CODE
  110.         # echo $_COUNTER
  111.         if [ "$T_CODE" = "$_CODE" ];then
  112.             return 0
  113.         else
  114.             if [ "$_COUNTER" -gt 3 ];then
  115.                 echo "Sorry incorrect code entered, you cannot change the settings..."
  116.                 return 1
  117.             fi
  118.         fi
  119.     done
  120. }

  121. check_drive()
  122. {
  123.     # make sure we can rewind the tape
  124.     mt -f /dev/$_DEVICE rewind > /dev/null 2>&1
  125.     if [ $? -ne 0 ];then
  126.         return 1
  127.     else
  128.         return 0
  129.     fi
  130. }

  131. #====================== main =======================

  132. # can we source the file
  133. check_source
  134. header
  135. # display the loaded in variables
  136. show_settings

  137. # ask user if he/she wants to change any settings
  138. if continue_prompt "Do you wish To Change Some of The System Defaults" "Y";
  139. then
  140.     echo $?    
  141.     # yes then enter code name
  142.     if get_code;then
  143.         # change some settings
  144.         change_settings
  145.     fi
  146. fi

  147. #------------------ got settings... now do backup
  148. if check_drive;then
  149.     echo "tape OK..."
  150. else
  151.     echo "Cannot rewind the tape..Is it in the tape drive???"
  152.     echo "check it out"
  153.     exit 1
  154. fi

  155. # file system paths to backup
  156. case $_TYPE in
  157.     Full|full)
  158.         BACKUP_PATH="sybase syb/suppor etc var bin apps usr/local"
  159.         ;;
  160.     Normal|normal)
  161.         BACKUP_PATH="etc var bin apps usr/local"
  162.         ;;
  163.     Sybase|sybase)
  164.         BACKUP_PATH="sybase syb/suppor"
  165.         ;;
  166. esac
  167. # now for backup
  168. cd /
  169. echo "Now starting backup......"
  170. find $BACKUP_PATH -print | cpio -ovB -O /dev/$_DEVICE >> $_LOGFILE 2>&1

  171. # if the above cpio does not work on your system try cpio below, instead
  172. # find $BACKUP_PATH -print | cpio -ovB > /dev/$_DEVICE >> $_LOGFILE 2>&1
  173. # to get more information on the tape change -ovB to -ovcC66536

  174. if [ "$_INFORM" = "yes" ];then
  175.     echo "Backup finished check the log file" | mail admin
  176. fi

backup.defaults

点击(此处)折叠或打开

  1. #!/bin/sh
  2. # backup.defaults
  3. # configuration default file for network backups
  4. # edit this file at your own
  5. # name backup.defaults
  6. # --------------------------------------------
  7. # not necessary for the environments to be in quotes.. but
  8. _CODE="comet"
  9. _LOGFILE="/appdva/backup/log.`date +%y%m%d`"
  10. _DEVICE="rmt0"
  11. _INFORM="yes"
  12. _TYPE="Full"
  13. #---------------------------------------------
  14. continue_prompt()
  15. {
  16.     # continue_prompt
  17.     # to call: continue_prompt "string to display" default_answer
  18.     _STR=$1
  19.     _DEFAULT=$2
  20.     # check we have the right params
  21.     if [ $# -lt 1 ];then
  22.         echo "continue_prompt: I need a string to display"
  23.         return 1
  24.     fi
  25.     while :
  26.     do
  27.         echo -n "$_STR [Y..N] [$_DEFAULT]:"
  28.         read _ANS
  29.         if [ "$_ANS" = "" ];then
  30.             : ${_ANS:=$_DEFAULT}
  31.             case $_ANS in
  32.                 Y) return 0
  33.                     ;;
  34.                 N) return 1
  35.                     ;;
  36.             esac
  37.         fi
  38.         # user has selected something
  39.         case $_ANS in
  40.             y|Y|Yes|YES)
  41.                 return 0
  42.                 ;;
  43.             n|N|No|NO)
  44.                 return 1
  45.                 ;;
  46.             *) echo "Answer either Y or N, default is $_DEFAULT"
  47.                 ;;
  48.         esac
  49.         echo $_ANS
  50.     done
  51. }

$./backup_run.sh backup.defaults
阅读(1616) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~