Last active
January 1, 2016 07:19
-
-
Save koy1619/8110381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BACKUP_SRC="/home/wwwroot" | |
BACKUP_DST="/home/backup" | |
#MYSQL_SERVER="localhost" | |
#MYSQL_USER="root" | |
MYSQL_PASS="123456" | |
# Stop editing here. | |
NOW=$(date +"%Y.%m.%d") | |
DESTFILE="$BACKUP_DST/$NOW.tar.gz" | |
# Backup files. | |
echo "Dumping databases..." | |
/usr/local/mysql/bin/mysqldump -u root -p$MYSQL_PASS database1 > "$NOW-database1.sql" | |
/usr/local/mysql/bin/mysqldump -u root -p$MYSQL_PASS database2 > "$NOW-database2.sql" | |
tar zcvf "$DESTFILE" $BACKUP_SRC "$NOW-database1.sql" "$NOW-database2.sql" | |
rm -f "$NOW-database1.sql" | |
rm -f "$NOW-database2.sql" | |
find ${BACKUP_DST} -ctime +7 | xargs rm -rf | |
DATE3=`date -d '-3 day' +"%Y.%m.%d"` | |
DELFile=${DATE3}.tar.gz | |
rm -f ${DELFile} |
crontab -e 0 4 * * * root /bin/sh /home/backup.sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
备份程序和sql,并删除7天以内的备份!