ScriptBackupMysql

My very own script to backup Mysql

Short, sweet and to the point: here is the script I use to backup Mysql really quickly.

WARNING This is a very basic script -- it does almost no checking at all. USE AT YOUR OWN RISK!! (You have been warned!)

#!/bin/bash

# #########################################################
# #
# # dump_mysql.sh			dump all mysql db
# #
# # v0.0 -- Gil ANDRE Tue Aug 14 15:40:50 CEST 2012
# #
# #########################################################

# today's date
today=$(date +%F-%H%M)

# dump file name
dump_file=$(hostname | awk -F\. '{print $1}')_${today}.SQLDUMP

# local admin password - remove "  "
local_password="put your MySQL admin password here"

# local admin account - remove "  "
local_admin="put your local MySQL admin account here"

# local mysql server - replace localhost if MySQL server is distant
local_server=localhost

# rm previous dump (no retention!)
rm /tmp/*.SQLDUMP*

# dump using mysqldump
$(which mysqldump) -A --add-drop-database --add-drop-table --quick -h ${local_server} -u ${local_admin} -p${local_password} > /tmp/${dump_file}

# compression - try compression schemes from best to worst
$(which xz || which bzip2 || which gzip) -9 /tmp/${dump_file}

# end of script.

Make sure you enter correct value for the variables named local_password, local_admin and local_server or the script will simply FAIL...

The script is set to backup all the Mysql databases into /tmp: make sure this FS has plenty of free space if you have large databases.

The clever trick is in searching for the best compression scheme... I am quite proud of this one! ;-)

Hope this helps!

Update!

Seriously, though, never, ever use this script when you can use Auto Mysql Backup. It's easy to set up, easy to use, and it works a hundred times better than the feeble attempt presented here.