Difference between revisions of "SUNScholar/Disaster Recovery/Backups"
| Line 90: | Line 90: | ||
To setup a similar system, first configure the server and then configure the clients. | To setup a similar system, first configure the server and then configure the clients. | ||
| − | === | + | ===[[SUNScholar/Disaster Recovery/Backups/Server Setup|Server Setup]]=== |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
===Client Setup=== | ===Client Setup=== | ||
Create an rsync config file. | Create an rsync config file. | ||
Revision as of 14:41, 10 August 2012
Contents
Local Backup
Here is a sample script to make local backups which are then sent to the remote backup server.
Type the following.
nano /usr/local/bin/backup.sh
Now copy and paste the following into the open editor and modify the backup variables to suit your location and server.
#!/bin/bash
## Setup the backup variables ##
LOCAL_SERVER="etd.sun.ac.za"
LOCAL_FOLDER="/var/backup"
BACKUP_LOGFILE="/var/log/backup.log"
# Day Of the Week
DOW=`date +%a`
TIME=`date`
{
## Timestamp the beginning of the backup ##
echo "Backup for $LOCAL_SERVER started: $TIME"
## Check that we have a backup folder ##
if [ ! -d $LOCAL_FOLDER ]; then
mkdir -p $LOCAL_FOLDER
echo "New backup folder created"
else
echo "Backup started: $TIME"
fi
## Make sure we're in / since backups are relative to that ##
cd /
## Get a list of the installed software ##
dpkg --get-selections > $LOCAL_FOLDER/installed-software.$DOW
## Backup the server config files ##
echo "Archive '/etc' folder"
tar czf $LOCAL_FOLDER/etc.tgz.$DOW etc/
## Backup the '/root' folder ##
echo "Archive '/root' folder"
tar czf $LOCAL_FOLDER/root.tgz root/
## Backup the '/usr/local' folder which houses customised software ##
echo "Archive '/usr/local' folder"
tar czf $LOCAL_FOLDER/usr-local.tgz usr/local/
## Backup the Dspace postgres database which houses the catalog of the digital assets ##
su - postgres -c "pg_dump dspace > /tmp/dspace-db.sql"
cp /tmp/dspace-db.sql $LOCAL_FOLDER/dspace-db.sql-$DOW
su - postgres -c "vacuumdb --analyze dspace > /dev/null 2>&1"
## View the backup folder ##
ls -lhS $LOCAL_FOLDER
## Timestamp the end of the backup ##
TIME=`date`
echo "Backup for $LOCAL_SERVER ended: $TIME"
} > $BACKUP_LOGFILE
## Make a daily copy of the backup log file ##
cp $BACKUP_LOGFILE $BACKUP_LOGFILE.$DOW
## Email the backup logfile to the root user ##
cat $BACKUP_LOGFILE.$DOW | mail -s "Daily backup log from $HOSTNAME" root
### EOF ###
Save the file with CTL+O and exit with CTL+X.
Now we make the backup script executable.
sudo chmod 0755 /usr/local/bin/backup.sh
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 Daily Backup Job
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.
Backup to Remote Server
The intention is to backup the files in /var/backup to a remote backup server. On our campus we have a server in a secure location for housing the remote backups. This server has a very large RAID disk storage and has Ubuntu 10.04 LTS installed. BackupPC is installed on the server. BackupPC uses the rsync method for pulling in the backups from the clients.
To setup a similar system, first configure the server and then configure the clients.
Server Setup
Client Setup
Create an rsync config file.
nano /etc/rsyncd.conf
Copy and paste the following.
[backup] path = /var/backup [home] path = /home
Enable the rsync server.
nano /etc/default/rsync
Change false to true.
RSYNC_ENABLE=true
Now you start the rsync server as follows:
/etc/init.d/rsync restart
Check the rysnc server.
rsync localhost::backup
rsync localhost::home
Now we add a firewall rule to allow the backup server to get to the backup files, type as follows:
ufw allow from %hostname% to any 873
Replace %hostname% with the hostname of your backup server.