Skip to content

Instantly share code, notes, and snippets.

@thomasjsn
Last active August 4, 2016 18:30
Show Gist options
  • Save thomasjsn/60e39c11daae90365e3737066431c7e4 to your computer and use it in GitHub Desktop.
Save thomasjsn/60e39c11daae90365e3737066431c7e4 to your computer and use it in GitHub Desktop.
Export all databases that the user can access, then sync the sql files to a s3 bucket.
#!/bin/bash
USER="backup"
PASSWORD="password"
OUTPUT="/output/folder"
BUCKET="backup-bucket"
databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
echo "Dumping database: $db"
mysqldump -u $USER -p$PASSWORD --databases $db > $OUTPUT/`date +%Y%m%d`.$db.sql
fi
done
s3cmd sync $OUTPUT/ s3://$BUCKET/sql/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment