MySQL mysqlhotcopy Script
Here’s a simple script to automate mysqlhotcopy runs from cron to backup multiple MySQL databases. The script loops through the list of databases and kicks off an instance of mysqlhotcopy in the background for each one. Really, nothing fancy.
#!/bin/bash db_user="dbusername" db_pass="dbuseroass" backup_dir="/home/databackup/" if [ -w "${backup_dir}" ] then for db_name in dbname1 dbname2 dbname3 do /usr/bin/mysqlhotcopy -u "${db_user}" -p "${db_pass}" "${db_name}" "${backup_dir}" --allowold --keepold & disown done fi
You can also backup all schemas without specifying their names:
#!/bin/bash db_user="dbusername" db_pass="dbuseroass" backup_dir="/home/databackup/" MYSQL="/usr/bin/mysql --batch --skip-column-names --max_allowed_packet=100M -u${db_user} -p${db_pass} -e" if [ -w "${backup_dir}" ] then for db_name in `$MYSQL "show databases;"` do /usr/bin/mysqlhotcopy -u "${db_user}" -p "${db_pass}" "${db_name}" "${backup_dir}" --allowold --keepold & disown done fi
No Comment »
1 Pingbacks »
[…] MySQL mysqlhotcopy Script […]