Skip to content

Instantly share code, notes, and snippets.

@arnekolja
Created January 7, 2010 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arnekolja/271643 to your computer and use it in GitHub Desktop.
Save arnekolja/271643 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script saves all databases in one file per database
# without the need to enumerate them. It just fetches a list
# of all databases and iterates over this list.
# Config part
user="root";
pass="rootpassword";
backup_path="/var/backups";
# No need to touch here
dbs=`mysql -u$user -p$pass -s -e "show databases;"`;
for db in $dbs
do
echo "Starting backup of database $db";
timestamp=`date +"%Y%m%d_%I%M"`;
filename=${backup_path}/${db}_${timestamp}.sql;
mysqldump -u$user -p$pass $db > ${filename};
echo "Compressing backup of $db";
gzip $filename;
echo "Backup of database $db finished.";
done
@conpassione
Copy link

For better human manageability of the backup-files, i would set the filename to ${timestamp}_${db}.sql
So you have all the backups of one day together. Its easier to delete old outdated backups...
Best Regards, Renzo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment