Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Backup files and databases to S3
DB_HOST="localhost"
DB_USER="xxx"
DB_PASS="xxx"
BUCKET="xxx"
DIR="/home/xxx"
#zip database
for DB in $(mysql --host=$DB_HOST --user=$DB_USER --password=$DB_PASS -e 'show databases' -s --skip-column-names); do mysqldump --host=$DB_HOST --user=$DB_USER --password=$DB_PASS $DB | gzip -9 > $DIR/../BACKUPS/DB/$DB.sql.gz; done;
#zip files
cd $DIR;
for i in */; do zip -r "$DIR/../BACKUPS/WEBS/${i%/}.zip" "$i"; done;
#upload s3
aws s3 mv $DIR/../BACKUPS s3://$BUCKET --recursive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment