Created
January 7, 2010 22:19
-
-
Save arnekolja/271643 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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