• linux shell 增量备份


    #! /bin/bash
    #Automatic Backup Linux System Files
    #By Author xiangbing
    #Define Variables

    SOURCE_DIR=(
      $*
    )

    TARGET_DIR=/data/backup
    YEAR=`date +%Y`
    MONTH=`date +%m`
    DAY=`date +%d`
    WEEK=`date +%u`
    FILES=system_backup.tgz
    CODE=$?

    if [ -z $SOURCE_DIR ]
    then
      echo -e "Please Enter a file or Directory You Need to Back: ----------------------------------------- Example $0 /boot/etc......"
      exit
    fi

    #Determine Whether the Target Directory Exists

    if [ ! -d $TARGET_DIR/$YEAR/$MONTH/$DAY ]
    then
      mkdir -p $TARGET_DIR/$YEAR/$MONTH/$DAY
      echo "this $TARGET_DIR Created Successfully"
    fi

    #EXEC full_backup Function Command

    full_backup()
    {
      if [ "$WEEK" -eq "7" ]
      then
        rm -rf $TARGET_DIR/snapshot
        cd $TARGET_DIR/$YEAR/$MONTH/$DAY
        tar -g $TARGET_DIR/snapshot -czvf $FILES `echo ${SOURCE_DIR[@]}`
        [ "$CODE" == "0" ] && echo -e "---------------------------------------------------------------- full_backup System Files Backup Successfully!"
      fi

    }

    #Perform incremental BACKUP Function Command
    add_backup()
    {
      cd $TARGET_DIR/$YEAR/$MONTH/$DAY
      if [ -f $TARGET_DIR/$YEAR/$MONTH/$DAY/$FILES ]
      then
        read -p "$FILES Already Exists,overwrite confirmation yes or no?:"SURE
        if [ $SURE == "no" -o $SURE == "n" ]
        then
        sleep 1; exit 0
        fi


        #add_backup Files System
        if [ $WEEK -ne "7" ]
        then
          cd $TARGET_DIR/$YEAR/$MONTH/$DAY
          tar -g $TARGET_DIR/snapshot -czvf $$_$FILES `echo ${SOURCE_DIR[@]}`
          [ "$CODE" == "0" ] && echo -e "------------------------------------------------------------------ add_backup System Files Backup Successfully!"
        fi
      else

        #add_backup Files System
        if [ $WEEK -ne "7" ]

        then
          cd $TARGET_DIR/$YEAR/$MONTH/$DAY
          tar -g $TARGET_DIR/snapshot -czvf $$_$FILES `echo ${SOURCE_DIR[@]}`
          [ "$CODE" == "0" ] && echo -e "------------------------------------------------------------------ add_backup System Files Backup Successfully!"
        fi
      fi

    }

    full_backup;add_backup

  • 相关阅读:
    gym 101480 Problem C: Cow Confinement 题解
    Uva 1072 Huffman Codes 题解
    NERC 2015 Hypercube 题解
    ACM ICPC 2017 WF Problem J Son of Pipe Stream题解
    CF Round # 295 (Div. 1)题解
    CF 1444 D Rectangular Polyline 题解
    BZOJ3308 九月的咖啡店
    BZOJ4025 二分图
    BZOJ4000 [TJOI2015]棋盘
    BZOJ3999 [TJOI2015]旅游
  • 原文地址:https://www.cnblogs.com/xiangbing123/p/15148047.html
Copyright © 2020-2023  润新知