Skip to content

Instantly share code, notes, and snippets.

@bugcy013
Forked from mrmichalis/mysqlbackup.sh
Created January 21, 2014 20:55
Show Gist options
  • Select an option

  • Save bugcy013/8548200 to your computer and use it in GitHub Desktop.

Select an option

Save bugcy013/8548200 to your computer and use it in GitHub Desktop.
#!/bin/bash
cd /home/$1/backups/
mkdir mysql
suffix=$(date +%y%m%d)
MYSQL="$(which mysql)"
databases="$($MYSQL -u $1 -p$2 -Bse ‘show databases’)"
for database in $databases
do
echo "Processing database $database"
mysqldump –opt -u$1 -p$2 ${database} > mysql/${database}.$suffix.sql
done
tar -cf archives/mysql_backup.$suffix.tar mysql/*
rm -r mysql/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment