Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » MySQL

MySQL mysqlhotcopy Script

Submitted by on December 2, 2013 – 1:30 pm

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

 

Print Friendly, PDF & Email

No Comment »

1 Pingbacks »

Leave a Reply

%d bloggers like this: