Last active
April 6, 2016 08:32
-
-
Save lucien144/6c00a7327ff45966eae3 to your computer and use it in GitHub Desktop.
Server backup - MySQL & Vhosts - to S3 usign s3cmd
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/bash | |
| # MySQL requirements | |
| # CREATE USER 'backup'@'localhost' IDENTIFIED BY 'secret'; | |
| # GRANT SELECT, SHOW VIEW, RELOAD, REPLICATION CLIENT, EVENT, TRIGGER ON *.* TO 'backup'@'localhost'; | |
| # GRANT LOCK TABLES ON *.* TO 'backup'@'localhost'; | |
| TIMESTAMP=$(date +"%A") | |
| DATE=$(date +"%F") | |
| BACKUP_DIR="./mysql-backup" | |
| MYSQL_USER="backup" | |
| MYSQL=/usr/bin/mysql | |
| MYSQL_PASSWORD="*****" | |
| MYSQLDUMP=/usr/bin/mysqldump | |
| mkdir -p "$BACKUP_DIR/$TIMESTAMP" | |
| databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"` | |
| for db in $databases; do | |
| $MYSQLDUMP -v --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/$TIMESTAMP/$db.gz" | |
| done | |
| if [ $(date +"%d") = "01" ]; then | |
| mkdir -p "$BACKUP_DIR/$DATE" | |
| cp -R $BACKUP_DIR/$TIMESTAMP/* "$BACKUP_DIR/$DATE/" | |
| fi | |
| s3cmd sync --recursive --delete-removed ./mysql-backup s3://server-backup-syd/ |
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/bash | |
| s3cmd sync --recursive --exclude-from=/root/backup/vhosts-backup.exclude /var/www/vhosts/ s3://server-backup-syd/vhosts-backup/ |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Todo: consider to use
automysqlbackuptool