Created
January 25, 2013 05:11
-
-
Save nLight/4631942 to your computer and use it in GitHub Desktop.
Backup over rsync
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/sh | |
# http://slava.uma.ru/?a=page&id=137 | |
BACKUP_DIR=/backup/fs | |
FILES_SRC=/root/adm/backup_src.lst | |
INCLUDE_FILES_PATTERN=/root/adm/backup_include.lst | |
EXCLUDE_FILES_PATTERN=/root/adm/backup_exclude.lst | |
BACKUP_DB_DIR=/backup/db | |
DB_BACKUP_PREFIX=db | |
MYSQL_HOST=localhost | |
MYSQL_USER=user | |
MYSQL_PASSWD=password | |
TIMESTAMP=`date '+%Y%m%d-%H%M%S'` | |
DAY=`date '+%d'` | |
FULL_BACKUP_DIR=$BACKUP_DIR/current | |
INC_BACKUP_DIR=$BACKUP_DIR/$DAY\_$TIMESTAMP | |
rm -f -R $BACKUP_DIR/$DAY\_* | |
nice -n 10 rsync -r --force --ignore-errors --delete --delete-excluded -av \ | |
--backup --backup-dir=$INC_BACKUP_DIR \ | |
--exclude-from=$EXCLUDE_FILES_PATTERN \ | |
--include-from=$INCLUDE_FILES_PATTERN \ | |
--files-from=$FILES_SRC \ | |
/ $FULL_BACKUP_DIR | |
rm -f $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_* | |
nice -n 10 /usr/bin/mysqldump --complete-insert --all-databases --force --all --add-drop-table \ | |
--host=$MYSQL_HOST \ | |
--password=$MYSQL_PASSWD \ | |
--user=$MYSQL_USER \ | |
| gzip >$BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_$TIMESTAMP.gz | |
nice -n 10 /usr/bin/mysqldump --complete-insert --all-databases --force --no-data --all --add-drop-table \ | |
--host=$MYSQL_HOST \ | |
--password=$MYSQL_PASSWD \ | |
--user=$MYSQL_USER \ | |
| gzip >$BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_struct\_$TIMESTAMP.gz | |
rm -f $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_current* | |
ln -s $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_$TIMESTAMP.gz $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_current.gz | |
ln -s $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_$DAY\_struct\_$TIMESTAMP.gz $BACKUP_DB_DIR/$DB_BACKUP_PREFIX\_current\_struct.gz | |
rm -f $BACKUP_DIR/current\_*.tar.gz | |
cd $BACKUP_DIR | |
nice -n 10 tar -zcf $BACKUP_DIR/current\_$TIMESTAMP.tar.gz * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment