SHELL脚本自动备份

Posted 生性凉薄

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SHELL脚本自动备份相关的知识,希望对你有一定的参考价值。

#!/bin/sh
#define
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 "$*" ];then
    echo -e "Please Enter Your Backup Files or Directories
--------------------------------------------
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 is 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  "--------------------------------------------
These 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 "These $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  "-----------------------------------------
These Add_Backup System Files Backup Successfully !"
   fi
else
   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  "-------------------------------------------
These Add_Backup System Files Backup Successfully !"
   fi
fi
}
Full_Backup;Add_Backup

参考的网址:http://blog.51cto.com/wgkgood/1330200

以上是关于SHELL脚本自动备份的主要内容,如果未能解决你的问题,请参考以下文章

MySql DUMP 自动备份数据库 Shell 脚本

MySql DUMP 自动备份数据库 Shell 脚本

SHELL脚本自动化备份MYSQL数据库

shell脚本 每天定时进行自动备份实战脚本~~~

shell脚本自动备份数据库

基于mysqldump编写自动全备增备的shell脚本