MySQL Backup Script Automysqlbackup

Install

To install it manually (the hard way).

  1. Create the /etc/automysqlbackup directory.
  2. Copy the automysqlbackup file to /usr/local/bin and make executable.
  3.  cp /etc/automysqlbackup/automysqlbackup.conf /etc/automysqlbackup/myserver.conf
  4. Edit the /etc/automysqlbackup/myserver.conf file to customise your settings.

USAGE

1. Create a script as below called runmysqlbackup using the lines below:

#~~~~ Copy From Below Here ~~~~
#!/bin/sh

/usr/local/bin/automysqlbackup /etc/automysqlbackup/myserver.conf

chown root.root /var/backup/db* -R
find /var/backup/db* -type f -exec chmod 400 {} \;
find /var/backup/db* -type d -exec chmod 700 {} \;

#~~~~~ Copy To Above Here ~~~~

2. Save it to a suitable location or copy it to your /etc/cron.daily folder.

3. Make it executable, i.e. chmod +x /etc/cron.daily/runmysqlbackup.


The backup can be run from the command line simply by running the following command.

  automysqlbackup /etc/automysqlbackup/myserver.conf

If you don't supply an argument for automysqlbackup, the default configuration
in the program automysqlbackup will be used unless a global file exists.

   /etc/automysqlbackup/automysqlbackup.conf

RESTORING

Firstly you will need to uncompress the backup file and decrypt it if encryption was used (see encryption section).

gunzip file.gz (or bunzip2 file.bz2)

Next you will need to use the mysql client to restore the DB from the sql file.

mysql --user=username --pass=password --host=dbserver database < /path/file.sql
or
  mysql --user=username --pass=password --host=dbserver -e "source /path/file.sql" database

NOTE: Make sure you use "<" and not ">" in the above command because you are piping the file.sql to mysql and not the other way around.