Enyo Backup
Views:
Contents |
MySQL
Enyo runs a script (via cron) to up backup the databases each night. Any databases which need to be backed up must be added to the "databases" array near the top of the script.
At the moment 7 days worth of backup are kept in /var/mysql-backups/<database name>/ .These are regularly backed up to tape, offering 5 weeks of database backups - See the next section.
#!/bin/bash
#
# DESCRIPTION:
# /bin/mysql-backup-script
# kjw
#
# Keeps 7 days of backups for local mysql databases. Also, the query cache is
# flushed to stop fragmentation.
#
# Needs a user account in mysql which has global SELECT, RELOAD and LOCK TABLE privilages.
# No other privilages should be given to the account!!
#
# SETTINGS:
backup_directory="/var/mysql-backups"
mysql_user="backup"
password="*************"
# Array of database names to backup
databases[0]="mysql"
databases[1]="varndeandyn"
####################################################
####################################################
####################################################
todays_date=`date +%G%m%d`
numberOfDBs=${#databases[@]}
count=0
while [ $count -lt $numberOfDBs ] # Loop through the array of database names
do
# Is there a sub directory to store backups from this database?
if [ -d ${backup_directory}/${databases[$count]} ]
then
# Directory exists, there might be some old backups we don't care about any more
# delete any backups that are more than 7 days old
find $backup_directory/${databases[$count]} -mtime +7 -iname ${databases[$count]}.????????.sql.gz -exec rm -f {}
else
# Directory doesn't exist, so create one
mkdir ${backup_directory}/${databases[$count]}
chgrp it-sup ${backup_directory}/${databases[$count]}
chmod 0770 ${backup_directory}/${databases[$count]}
fi
# create a new backup for today
/usr/bin/mysqldump -u $mysql_user -p${password} --database ${databases[$count]}|gzip -9 > ${backup_directory}/${databases[$count]}/${databases[$count]}.${todays_date}.sql.gz
# set appropriate permissions
chgrp it-sup ${backup_directory}/${databases[$count]}/${databases[$count]}.${todays_date}.sql.gz
chmod 0660 ${backup_directory}/${databases[$count]}/${databases[$count]}.${todays_date}.sql.gz
# Increment the counter so we move on to the next database
(( count++ ))
done
# Flush (defragment) the MySQL Query Cache
/usr/bin/mysql -u $mysql_user -p${password} -e "flush query cache;"
# Just incase something naughty is appended to the file
exit 0 # Bye! :)
Filesystem Backup
The following areas of the filesystem are backed up to ares via rsync:
- /etc/
- /var/www/
- /var/mysql-backups
The files are stored on ares in /var/enyo-backup.
SSH is used as the transport for rsync to allow for the data to be encrypted. In order to script the backup, plain text key authentication is used between the servers (other wise a password would need to be entered interactively.
Enyo has a user account called backup. The root user on ares has an rsa key, the public has been copied to the /home/backup/.ssh/ folder on enyo. The backup user has no special permissions so some files will not be automatically backup up - i.e. files with out global read permissions.
The simple backup script runs dialy via a cron job on ares:
#!/bin/bash # #/bin/enyo-backup-script #kjw rsync -baze ssh --exclude-from=/root/rsync.etc.exclude backup@enyo.varndean.ac.uk:/etc /var/enyo-backup rsync -bzae ssh backup@enyo.varndean.ac.uk:/var/mysql-backups /var/enyo-backup rsync -bzae ssh --delete --exclude /var/www/moodle backup@enyo.varndean.ac.uk:/var/www /var/enyo-backup # These next two lines are added here for convenience and simplicity, these lines actually backup up moodle FROM ARES TO ENYO! rsync -bzae ssh --delete --excule-from=/root/moodle.rsync.exclude /srv/www/moodle/ backup@enyo.varndean.ac.uk:/var/www/moodle/ rsync -bzae ssh /var/lib/mysql5-backup/moodle.1.sql.gz backup@enyo.varndean.ac.uk:/var/www/moodle/ares-moodle-db-backup.sql.gz exit 0
