Created
December 29, 2014 12:32
-
-
Save ykarikos/02e5fce8ab2ee6c83bac to your computer and use it in GitHub Desktop.
Backup script
This file contains hidden or 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 -e | |
HOME="/home/user" | |
HOST="foobar" | |
BACKUP_DIR="/var/backup/$HOST" | |
BACKUP_FILE="$HOST-`date -I`.tar.bz2.gpg" | |
MYSQL_FILE="mysql-`date -I`.bak.gpg" | |
RECIPIENT="[email protected]" | |
cd $BACKUP_DIR | |
tar jc --one-file-system -X /etc/backup-exclude -C / etc var usr/local| | |
gpg -z 0 --batch -qer $RECIPIENT >$BACKUP_FILE | |
md5sum $BACKUP_FILE >$BACKUP_FILE.md5 | |
/usr/bin/mysqldump -u root --password='secret' --all-databases | | |
gpg -z 9 --batch -qer $RECIPIENT >$MYSQL_FILE | |
# Remove old backups | |
ls -tr | head -n -9 | xargs rm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment