首页 > 其他 > 详细

全量增量备份目录脚本

时间:2019-08-03 23:16:04      阅读:107      评论:0      收藏:0      [点我收藏+]
#!/bin/sh
#auto full or 增量 backup
#by zkg 2019-07-10

#定义变量
SOURCE_DIR=/opt/shell/
BACKUP_DIR=/tmp
YEAR=date +%Y
MONTH=date +%m
DAY=date +%d
WEEK=date +%u
A_TIME=date +%H%M
FILES=${A_TIME}_shell_backup.tar.gz

if [ ! -d $SOURCE_DIR ];then
echo "this $SOURCE_DIR is not exist..."
exit
fi

#判断备份目录是否存在,不存在则创建
if [ ! -d $BACKUP_DIR/$YEAR/$MONTH/$DAY ];then
mkdir -p $BACKUP_DIR/$YEAR/$MONTH/$DAY
echo -e "\033[32mthe $BACKUP_DIR/$YEAR/$MONTH/$DAY created successfully\033[0m"
fi

#定义周日进行全量备份函数
Full_backup()
{
if [ "$WEEK" -eq 7 ];then
rm -rf $BACKUP_DIR/snapshot
cd $BACKUP_DIR/$YEAR/$MONTH/$DAY ;tar -g $BACKUPDIR/snapshot -czvf FULL$FILES $SOURCE_DIR
if [ $? -eq 0 ];then
echo -e "----------------\n\033[32mthis Full_backup is successfully!\033[0m"
else
echo -e "----------------\n\033[32mthis Full_backup is Failed!\033[0m"
exit 0
fi
fi
}
#定义其他天进行增量备份函数
Add_backup()
{
if [ "$WEEK" -ne 7 ];then
cd $BACKUP_DIR/$YEAR/$MONTH/$DAY ;tar -g $BACKUPDIR/snapshot -czvf ADD$FILES $SOURCE_DIR
if [ $? -eq 0 ];then
echo -e "----------------\n\033[32mthis Add_backup is successfully!\033[0m"
else
echo -e "----------------\n\033[32mthis Add_backup is Failed!\033[0m"
exit 0
fi
fi
}
sleep 3
Full_backup;Add_backup

全量增量备份目录脚本

原文:https://blog.51cto.com/1009516/2426140

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!