Skip to content

Instantly share code, notes, and snippets.

@johnbeynon
Last active August 29, 2015 13:57
Show Gist options
  • Save johnbeynon/9887761 to your computer and use it in GitHub Desktop.
Save johnbeynon/9887761 to your computer and use it in GitHub Desktop.
Backup commands for MySQL and Postgres - backs up all databases!
# backup_all_dbs.sh
# Expects ~/backups to exist
# Expects pg to be running on 127.0.0.1
# Expects mysql to be running on 127.0.0.1
# Expects mysql root user to have no password
# Expects zip to be available.
echo "Backing up local DBs"
pg_dumpall -h 127.0.0.1 > ~/backups/postgres.sql
mysqldump -u root --all-databases > ~/backups/mysql.sql
echo "Remove existing backups"
rm ~/backups/postgres.zip
rm ~/backups/mysql.zip
echo "ZIP new backups"
cd ~/backups
zip postgres.zip postgres.sql
zip mysql.zip mysql.sql
echo "Remove .sql files"
rm postgres.sql
rm mysql.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment