フル・バックアップとインクリメンタル・バックアップ・スクリプト



フル・バックアップとインクリメンタル・バックアップ・スクリプト
 
#!/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
Usage: { $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