1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #!/bin/bash
BACKUP=/home/dbback TMPBACKUP=/tmp/dbback
DATETIME=$(date +%Y%m%d%H%M%S)
# 打印日志 function log_correct () { USER=$(whoami) echo "${DATETIME} ${USER} execute $0 [INFO] $@ " >> "/home/shell/backup_log.txt" }
# 创建备份目录 mkdir -p "${TMPBACKUP}/$DATETIME"
cd ${TMPBACKUP}/$DATETIME/ cp /home/java/xzl/h2/* ./ tar -cvf $DATETIME.tar *.db
mv $DATETIME.tar $BACKUP
cd $BACKUP
# 删除7天前的文件 #find $BACKUP -type f -mtime +7 -exec rm -f {} \;
log_correct "数据库备份到:${BACKUP} 下"
|