This is an old revision of the document!
Table of Contents
Backups
We utilize three methods for backups:
Example Scripts
Example scripts to be used on ILRI servers for automated backup and maintenance of data. Most should be configured to run via cron, usually as root. Make sure that any critical scripts are protected by changing the permissions to 700 so only root can read them.
To add a cron entry, edit root's cron tab:
$ sudo crontab -e
… to contain the following lines:
# Backup the MySQL database at 12:13 every night 13 0 * * * /home/backup/scripts/backup_mysql.sh
Which will run the script every night at 12:13.
Backup MySQL Database
This script will dump a given database to a mysql folder in the specified backup directory. Make sure the backup directory and the mysql subdirectory exist.
#!/bin/sh
BACKUP_DIR=/home/backup
DATE=$(date +%Y%m%d)
mysqldump --opt -u root -p'yourpassword' databasename | bzip2 -c > ${BACKUP_DIR}/mysql/databasename_${DATE}.sql.bz2
exit 0
Backup PostgreSQL Database
This script will dump a given database to a postgres folder in the specified backup directory. Make sure the backup directory and the postgres subdirectory exist.
#!/bin/sh
# set the user's Postgres password in the variable because we are
# not using pg_dump interactively, so we can't type it in!
export PGPASSWORD="database password"
# Grab the current date and save it to the DATE variable.
# February 22, 2010 would look like this: 20100222
DATE=$(date +%Y%m%d)
# Backup the PostgreSQL dspace database at 12:15 every night
/usr/bin/pg_dump -b -v -o --format=custom -U user /home/backup/postgres/database_${DATE}.backup database
exit 0
Cleanup Old Backups
This script will search the specified backup directory for backup files older than 2 weeks and delete them. Make sure you don't delete backup scripts or non-backup files (directories, maybe?).
#!/bin/sh
BACKUP_DIR="/home/backup"
# Find files older than 2 weeks and delete them
find ${BACKUP_DIR} -type f \! -newermt "2 weeks ago" \! -name "*.sh" -exec rm {} \;
exit 0
