Difference between revisions of "Database Backup"

From Amahi Wiki
Jump to: navigation, search
Line 3: Line 3:
 
== Installation ==
 
== Installation ==
 
* Create a share called '''Database''' with the path of ''/var/hda/files/db''.
 
* Create a share called '''Database''' with the path of ''/var/hda/files/db''.
* Download the script [http://downloads.sourceforge.net/project/automysqlbackup/AutoMySQLBackup/AutoMySQLBackup%20VER%202.5/automysqlbackup-2.5.1-01.sh AutoMySQLBcckup] file to ''/tmp'' directory.
+
* Download the script [http://downloads.sourceforge.net/project/automysqlbackup/AutoMySQLBackup/AutoMySQLBackup%20VER%202.5/automysqlbackup-2.5.1-01.sh AutoMySQLBackup] file to ''/tmp'' directory.
 
  cd /tmp
 
  cd /tmp
 
  wget http://downloads.sourceforge.net/project/automysqlbackup/AutoMySQLBackup/AutoMySQLBackup%20VER%202.5/automysqlbackup-2.5.1-01.sh
 
  wget http://downloads.sourceforge.net/project/automysqlbackup/AutoMySQLBackup/AutoMySQLBackup%20VER%202.5/automysqlbackup-2.5.1-01.sh
Line 28: Line 28:
 
  cd /etc/cron.daily
 
  cd /etc/cron.daily
 
  ln -s /usr/local/bin/automysqlbackup-2.5.1-01.sh
 
  ln -s /usr/local/bin/automysqlbackup-2.5.1-01.sh
*
+
* When it's run the first time, it will create the directory structure automatically.  It will look like this:
 +
daily
 +
latest
 +
monthly
 +
weekly
 +
* Each time it is executed, the script will backup all your databases and tables.  Each database will be exported in to ''.sql'' files, zipped, and placed in its own folder for the respective period, i.e. latest, daily, etc.  The sql will include the database/table create syntax as well. 
 +
* It will also rotate those each time so you will have backups preserved for quite some time.
  
 
== Tips ==
 
== Tips ==

Revision as of 16:40, 11 November 2010

It's good practice to periodically backup up your database. This functionality is coming to Amahi soon, but until then there is a simple way to automatate it. Follow the steps below to help keep your data safe.

Installation

  • Create a share called Database with the path of /var/hda/files/db.
  • Download the script AutoMySQLBackup file to /tmp directory.
cd /tmp
wget http://downloads.sourceforge.net/project/automysqlbackup/AutoMySQLBackup/AutoMySQLBackup%20VER%202.5/automysqlbackup-2.5.1-01.sh
  • Some changes will need to be made for this to work on your HDA. Use your favorite text editor and update as follows:

USERNAME=debian on line 39 to:

USERNAME=root

PASSWORD= on line 42 to:

PASSWORD=hda

BACKUPDIR="/srv/backup/db" on line 51 to:

BACKUPDIR="/var/hda/files/db"

MAILADDR="maintenance@example.com" on line 65 to:

MAILADDR="root"

DBEXCLUDE="" on line 76 to:

DBEXCLUDE="information_schema"

CREATE_DATABASE=no on line 79 to:

CREATE_DATABASE=yes

LATEST=no on line 94 to:

LATEST=yes
  • Copy the file from /tmp to /usr/local/bin and set the permissions:
cd /usr/local/bin
cp /tmp/automysqlbackup-2.5.1-01.sh .
chmod 755 automysqlbackup-2.5.1-01.sh
  • Set as a daily cron job:
cd /etc/cron.daily
ln -s /usr/local/bin/automysqlbackup-2.5.1-01.sh
  • When it's run the first time, it will create the directory structure automatically. It will look like this:
daily
latest
monthly
weekly
  • Each time it is executed, the script will backup all your databases and tables. Each database will be exported in to .sql files, zipped, and placed in its own folder for the respective period, i.e. latest, daily, etc. The sql will include the database/table create syntax as well.
  • It will also rotate those each time so you will have backups preserved for quite some time.

Tips