Jeremy’s World

Jeremy de Oliveira-Kumar’s website about interesting stuff

Entries Comments



Backing up a mysql server

26 April, 2008 (20:03) | Databases, Linux, News, Shell Scripts | By: Jeremy

In an increasingly data dependant world, backing up has never been more important.  This especially applies to databases on servers.  It is shocking to know how many people fail to backup their data out of sheer ignorance or a failure to understand the purpose of backing up until its too late (I used to be one of those people, but then I was young and didn’t have much worthwhile data on my computer anyway).

With the advent of the LAMP server architecture, mysql databases are increasingly in use on servers (this is now even more true now with Ruby On Rails setups).  In order to protect all my database data, I wrote a quick and simple script using existing mysql tools found in most linux setups to perform a hot backup.  This backup can be for a single database or the entire DBMS.

The script is called mysql-backup and to describe simply it performs the following operations:

  1. Setup the filename for the backup with the current date and time
  2. Set the backup folder (/var/lib/mysql/backup - a standard folder in Ubuntu setups)
  3. Do a backup of all databases (the –all-databases line can be customised if you wish to only backup a single database on your server)
  4. Purge any older backups prior to the last 10 (if 10 already exist - this line can be commented out if you wish to keep all backups, but note that this might take up a lot of space in the long run)

The best way to run the script is through a cron job.  I usually perform my database backups at least once a day on low demand machines, and twice daily on high use http servers.

You can find a copy of the script on the Linux Scripts page of this site.

Linux Scripts

25 April, 2008 (21:06) | News | By: Jeremy

On this page I have provided a collection of primarily shell scripts freely available for those who wish to use them.  If you wish to make modifications to these scripts please let me know - I would be interested in your ideas to improve or change the way these scripts work.

Backup Scripts

http://www.eremyjay.com/wp-content/plugins/downloads-manager/img/icons/default.gif cyrus-backup.sh (20.85KB)
added: 24/04/2008
clicks: 24
Cyrus-Backup is a script for use on unix-based operating systems to help backup a cryrus mail server database. It performs offline backups of cyrus data and provides a host of parameters for setting how you wish to perform a backup. Based on mailbfr, a script specific to os x servers, this version has been customised to work on Ubuntu linux, but can easily be altered via the list of parameters for alternate flavours of linux and unix-based systems.

http://www.eremyjay.com/wp-content/plugins/downloads-manager/img/icons/default.gif mysql-backup.sh (938B)
added: 24/04/2008
clicks: 14
This is a special script to backup your entire mysql dbms. It performs a hot backup of all databases to a location specified in the script arguments. This script is useful for those administrators who need a regular backup of their dbms. Note that the mysql admin tools should be installed on the operating system (normally provided with mysql).