• Increase font size
  • Default font size
  • Decrease font size

How to backup mysql database using AutoMySQLBackup

With mysqldump anyone can write a small shell script and running it from cron, it will achieve an automatic backup solution

AutoMySQLBackup can backup a single database, multiple databases, or all the databases on the server; each database is saved in a separate file that can be compressed (with gzip or bzip2); it will rotate the backups and not keep them filling your hard drive (as normal in the daily backup you will have only the last 7 days of backups, the weekly if enabled will have one for each week, etc.).

# Username to access the MySQL server e.g. dbuser
USERNAME=dbuser

# Username to access the MySQL server e.g. password
PASSWORD=password

# Host name (or IP address) of MySQL server e.g localhost
DBHOST=localhost

# List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
DBNAMES="DB1 DB2 DB3"

# Backup directory location e.g /backups
BACKUPDIR="/var/backup/mysql"


You can also run the script manually:

./automysqlbackup.sh.2.5

You can just dump it in the /etc/cron.daily/ folder and you should be done.  .
Myself I like to place it in /opt and create a symlink to the file (to help with future updates of the script):

ln -s automysqlbackup.sh.2.5 automysqlbackup.shand run it from cron by placing in /etc/crontab something like:

#MySQL Daily backup
45 5   * * *   root    /opt/automysqlbackup.sh >/dev/null 2>&1

Download AutoMySQLBackup

 

Add comment


Security code
Refresh