PhenoTips » Administration Guide » Daily database backups

Daily database backups

Daily database backups

These instructions are valid for a PhenoTips server running on linux, under Tomcat, with MySQL as the database system.

Manual backups

This script can be used to create a new database backup. By default it uses the connection details configured in the running PhenoTips instance, and saves the backup in a file named data-<yyyy-mm-dd>.sql in the directory /var/lib/phenotips/backups/mysql/.

To use the script, simply download it and execute it from the server.

wget http://phenotips.org/download/PhenoTips/Backups/backup-phenotips-database.sh
chmod +x backup-phenotips-database.sh
./backup-phenotips-database.sh

To save the data in a different directory, run:

BACKUPDIR=/path/to/directory/ ./backup-phenotips-database.sh

To save the data in a file named data.sql, without the date in the filename, pass undated as the first parameter:

./backup-phenotips-database.sh undated

Automatic periodical backups

crontab can be used to automatically run the script at given intervals. For example, to automatically backup each day at midnight, run crontab -e and put this in the editor that shows up:

0 0 * * * $HOME/backup-phenotips-database.sh
Make sure the user running this crontab has write access to the target directory, /var/lib/phenotips/backups/mysql/
Use the proper path to the backup script, if it is not placed in the user's home directory

Rotating backups

logrotate can be used to automatically discard older backups, keeping only a few daily backups, and then increasingly rare weekly, monthly, and yearly backups. This logrotate configuration saves:

  • daily backups for a week
  • weekly backups for a month
  • monthly backups for a year
  • yearly backups for a decade

To use it, download the configuration and enable it in crontab -e

0 0 * * * $HOME/backup-phenotips-database.sh undated ; logrotate -f $HOME/backup-phenotips.logrotate.conf
For the logrotate to work, the backup script must be executed with the undated option