完整备份和增量备份脚本

 

完整备份和增量备份脚本

 

#!/bin/bash
#full incremental backup test
#by lijunmin 20171021

#一周一次完整备份,一天一次增量备份
SOURCE_DIR=(
    $*
)
TARGET_DIR=/data/backup/
YEAR=`date +%Y`
MONTH=`date +%m`
DAY=`date +%d`
WEEK=`date +%u`
BAK_NAME=`date +%H%M`
FILES=${BAK_NAME}_system_backup.tgz
CODE=$?
if [ -z "$*" ];then
    echo -e "\033[32mPlease enter your backup files or directories\nUsage: { $0 /boot /etc}\033[0m"
    exit
fi

#检查备份文件路径是否存在
if [ ! -d $TARGET_DIR/$YEAR/$MONTH/$DAY ];then
    mkdir -p $TARGET_DIR/$YEAR/$MONTH/$DAY
    echo -e "\033[32mThe $TARGET_DIR created successfully\033[0m"
fi

#EXEC FULL_BACKUP FUNCTION COMMAND
Full_Backup(){
if [ "$WEEK" -eq "6" ];then
    rm -fr $TARGET_DIR/snapshot
    cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;tar -g $TARGET_DIR/snapshot -czvf $FILES ${SOURCE_DIR[@]}
    [ "$CODE" == "0" ] && echo -e "\033[32mThe full_backup system files backup successfully\033[0m"
fi
}

#执行增量备份函数命令
Add_Backup(){
if [ "$WEEK" -ne "6" ];then
    rm -fr $TARGET_DIR/snapshot
    cd $TARGET_DIR/$YEAR/$MONTH/$DAY ;tar -g $TARGET_DIR/snapshot -czvf $BAK_NAME$FILES ${SOURCE_DIR[@]}
    [ "$CODE" == "0" ] && echo -e "\033[32mThe add_backup $FILES system files backup successfully\033[0m"
fi
}

sleep 3
Full_Backup;Add_Backup

 

 

你可能感兴趣的:(数据库)