PKP/Backups

Back to System Admin

Create the backup folder
mkdir /var/backup

Rsync
Enable "rsync" in the /etc/default folder nano /etc/default/rsync

Then create an rsync config file. nano /etc/rsyncd.conf [backup] path = /var/backup

[home] path = /home

[www] path = /var/www

[ojs] path = /var/ojs

[ocs] path = /var/ocs Start rsync /etc/init.d/rsync restart Do a listing check rsync localhost::www

Backup Script
Create a backup script nano /usr/local/bin/backup.sh Copy and paste the following.

Change the %hostname% variable.
 * 1) !/bin/bash

LOCAL_SERVER="%hostname%" LOCAL_FOLDER="/var/backup" BACKUP_LOGFILE="/var/log/backup.log" DOW=`date +%a` TIME=`date`
 * 1) Setup the backup variables ##
 * 1) Day Of the Week

{ echo "Backup for $LOCAL_SERVER started: $TIME"
 * 1) Timestamp the beginning of the backup ##

if [ ! -d $LOCAL_FOLDER ]; then mkdir -p $LOCAL_FOLDER echo "New backup folder created" else echo "Backup started: $TIME" fi
 * 1) Check that we have a backup folder ##

cd /
 * 1) Make sure we're in / since backups are relative to that ##

dpkg --get-selections > $LOCAL_FOLDER/installed-software.$DOW
 * 1) Get a list of the installed software ##

which -a mysql if [ $? == 0 ] ; then echo "SQL dump of MySQL database" mysqldump -A > $LOCAL_FOLDER/mysql-db-$DOW.sql fi
 * 1) Backup MySQL database (Check for a root .my.cnf file)

echo "Archive '/etc' folder" tar czf $LOCAL_FOLDER/etc.tgz.$DOW etc/
 * 1) Backup the server config files ##

echo "Archive '/root' folder" tar czf $LOCAL_FOLDER/root.tgz root/
 * 1) Backup the '/root' folder ##

echo "Archive '/usr/local' folder" tar czf $LOCAL_FOLDER/usr-local.tgz usr/local/
 * 1) Backup the '/usr/local' folder which houses customised software ##

ls -lhS $LOCAL_FOLDER
 * 1) View the backup folder ##

TIME=`date` echo "Backup for $LOCAL_SERVER ended: $TIME" } > $BACKUP_LOGFILE
 * 1) Timestamp the end of the backup ##

cp $BACKUP_LOGFILE $BACKUP_LOGFILE.$DOW
 * 1) Make a daily copy of the backup log file ##

cat $BACKUP_LOGFILE.$DOW | mail -s "Daily backup log from $HOSTNAME" root
 * 1) Email the backup logfile to the root user ##

Make the script executeable chmod 0755 /usr/local/bin/backup.sh
 * 1) EOF ###

Crontab
Here is a sample script to use for backups. It backups each day at midnight for a week only. A cron job entry is added to the root crontab to run the script at midnight each day. To add the script to the root crontab type the following as the root user: crontab -e

@midnight   /usr/local/bin/backup.sh Save and exit the crontab editor.

Invoke Local Manual Backup
After you have completed the above, you can start a backup anytime by typing the following as the root user: /usr/local/bin/backup.sh Then check the files in the backup folder by typing the following: ls -lh /var/backup

Setup Remote Backups

 * http://wiki.lib.sun.ac.za/index.php/SUNScholar/Disaster_Recovery/Backups/Server_Setup