Chinaunix首页 | 论坛 | 博客
  • 博客访问: 74250
  • 博文数量: 47
  • 博客积分: 1230
  • 博客等级: 中尉
  • 技术积分: 525
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-22 13:59
文章分类

全部博文(47)

文章存档

2012年(9)

2011年(38)

分类: Python/Ruby

2011-04-25 18:05:12

 

  1. #./bin/bash
  2. #Function:backup directory 'data' to dest 'qvbackp'
  3. #Date:2011 04 25
  4. #Version:1.0.0.0

  5.  declare -i count=$#
  6. # step1:backup
  7.  case $count in
  8.      "1") # ....
  9.         if [ "$1" == "--help" ] ; then
  10.            echo "Usage. qvbackup.sh SOURCE-DIRECTORY DEST-DIRECTORY"
  11.            echo "Backup files of SOURCE-DIRECTORY to DEST-DIRECTORY."
  12.          elif
  13.            echo "Invalid parameters, make sure all parameters are correct. "
  14.          fi
  15.  ;;
  16.       "2") #...
  17.           #..... ........ .......
  18.           if [ ! -d $1 ] ;then
  19.              echo "No such file or directory"
  20.           elif [ ! -d $2 ] ;then
  21.              mkdir -p $2
  22.           fi
  23.           #.............. ........
  24.           if [ -d $1 ] && [ -d $2 ]
  25.           srcdir=$(dirname $1)
  26.           srcname=$(basename $1)
  27.           destdir=$2
  28.           destdir="${destdir%/}/" #............./.....
  29.           backupfile="$(date +%Y-%m-%d-%H-%M-%S)_$srcname.tgz"
  30.           destfile="$destdir$backupfile"
  31.           pushd $srcdir
  32.           tar -g "${destdir}snapshot" -zcf $destfile $srcname
  33.           popd
  34.  ;;
  35.       "0") # ....
  36.          echo "No parameters, please make sure."
  37.  ;;
  38.        *) # ......
  39.          echo "Too more parameters, please make sure."
  40.  ;;
  41. esac

  42. #setp2 output backup log and backup information
  43. pushd $destdir
  44. rstMsg=""
  45. if [ find . -name $backupfile ] ; then
  46.    rstMsg="$(date +%Y-%m-%d-%H-%M-%S) backup OK"
  47.    flag=1
  48. else
  49.    rstMsg="$(date +%Y-%m-%d-%H-%M-%S) backup ERROR"
  50. fi
  51. echo $rstMsg>>qvbackup.log

  52. #setp3 recover scripts
  53. if [ "flag" == "1" ] ; then
  54.    echo "tar zxf $destfile ">>qvrecover.sh
  55. fi
阅读(735) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:0422

给主人留下些什么吧!~~