Skip to content

Instantly share code, notes, and snippets.

@ulfklose
Forked from arnekolja/mysqlbackup.sh
Created April 24, 2010 22:42
Show Gist options
  • Save ulfklose/378013 to your computer and use it in GitHub Desktop.
Save ulfklose/378013 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment