Difference between revisions of "SUNScholar/Disaster Recovery/Backups"

From Libopedia
Jump to navigation Jump to search
 
(63 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Local Backup==
+
<center>
Here is a sample script to make local backups which are then sent to the remote backup server.
+
'''[[SUNScholar/Disaster Recovery|Back to Disaster Recovery]]'''
 +
</center>
 +
==Introduction==
 +
===Architecture===
 +
#Each backup server is in a different building.
 +
#Each building is separately located on campus.
 +
#Each backup server uses Ubuntu LTS server software.
 +
#Each backup server has BackupPC installed.
 +
#BackupPC is setup to use the '''"rsyncd"''' method for pulling in the backups from the production servers.
  
Type the following.
+
[[File:Disaster-recovery.png|555px|border]]
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.
 
<pre>
 
#!/bin/bash
 
  
## Setup the backup variables ##
+
===Methodology===
LOCAL_SERVER="etd.sun.ac.za"
+
* Step 1. A local database backup is performed daily on the production server to be backed up.
LOCAL_FOLDER="/var/backup
+
* Step 2. The local database backup and the /home/dspace folder on the production server are then copied/synced to both backup servers which use BackupPC.
BACKUP_LOGFILE="/var/log/backup.log"
 
# Day Of the Week
 
DOW=`date +%a`
 
TIME=`date`
 
  
{
+
==Instructions==
## Timestamp the beginning of the backup ##
+
===[[SUNScholar/Disaster Recovery/Backups/Client Setup|Step 1 - Production Client Server Setup]]===
echo "Backup for $LOCAL_SERVER started: $TIME"
 
  
## Check that we have a backup folder ##
+
===[[SUNScholar/Disaster Recovery/Backups/Server Setup|Step 2 - Individual Backup Server Setup]]===
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 ##
+
==YouTube Video==
cd /
+
<html5media width="560" height="315">https://www.youtube.com/watch?v=Tno6niMqCNY</html5media>
 
+
==References==
## Get a list of the installed software ##
+
*http://sourceforge.net/projects/backuppc
dpkg --get-selections > $LOCAL_FOLDER/installed-software.$DOW
+
*https://en.wikipedia.org/wiki/BackupPC
 
+
*http://wiki.centos.org/HowTos/BackupPC
## Backup the server config files ##
+
----
echo "Archive '/etc' folder"
+
*http://en.wikipedia.org/wiki/Rsync
tar czf $LOCAL_FOLDER/etc.tgz.$DOW etc/
+
*http://rsync.samba.org
 
+
----
## Backup the '/root' folder ##
+
*https://www.digitalocean.com/community/tutorials/how-to-use-backuppc-to-create-a-backup-server-on-an-ubuntu-12-04-vps
echo "Archive '/root' folder"
+
*http://serverfault.com/questions/237969/backuppc-are-full-backups-really-full-when-using-rsync
tar czf $LOCAL_FOLDER/root.tgz root/
+
*http://www.backupcentral.com/phpBB2/two-way-mirrors-of-external-mailing-lists-3/backuppc-21/howto-create-and-keep-yearly-backups-77176/
 
+
[[Category:System Administration]]
## 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 ###
 
</pre>
 
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===
 
It is assumed you will be using Ubuntu 10.04 LTS for the backup server. If so, do the following to set it up as the '''backuppc''' server.
 
 
 
Login and become the root user.
 
 
 
Create a firewall rule for each client to be backed up as follows:
 
ufw allow from %my-client-to-be-backed-up-ipaddress% to any
 
 
 
Now test your rsync connection to each client as follows:
 
rsync %my-client-to-be-backed-up-ipaddress%::backup
 
You should get a listing of the backup files in the clients '''/var/backup''' folder.
 
 
 
If the above is successful then install '''backuppc''' on the server as follows:
 
apt-get install backuppc
 
BackupPC has a web interface which you enable as follows:
 
cd /etc/apache2/conf.d
 
 
 
ln -s /etc/backuppc/apache.conf backuppc
 
 
 
/etc/init.d/apache2 restart
 
 
 
Now we add an admin backuppc user as follows:
 
 
 
htpasswd /etc/backuppc/htpasswd admin
 
You will prompted to enter a password twice
 
 
 
Now open a web browser and type the following into the address bar:
 
http://%my-backup-server/backuppc
 
You will be prompted for the username and password that you set up above.
 
 
 
After logging in and clicking on "Host Summary", you should be presented with a screen like the following:
 
 
 
[[File:Backuppc-1.png|900px|border]]
 
 
 
Now setup backuppc by adding host configurations. There is plenty of backuppc documentation out there.
 
 
 
However, below is an example screenshot of the critical configuration, '''Xfer''' settings, that are done per host. Check out highlighted boxes in red.
 
 
 
[[File:Backuppc-2.png|900px|border]]
 
 
 
Continue to setup backuppc as needed. That's it.
 
 
 
===Client Setup===
 
Create an rsync config file.
 
nano /etc/rsyncd.conf
 
Copy and paste the following.
 
<pre>
 
[backup]
 
path = /var/backup
 
 
 
[home]
 
path = /home
 
</pre>
 
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.
 

Latest revision as of 12:15, 29 July 2016

Back to Disaster Recovery

Introduction

Architecture

  1. Each backup server is in a different building.
  2. Each building is separately located on campus.
  3. Each backup server uses Ubuntu LTS server software.
  4. Each backup server has BackupPC installed.
  5. BackupPC is setup to use the "rsyncd" method for pulling in the backups from the production servers.

Disaster-recovery.png

Methodology

  • Step 1. A local database backup is performed daily on the production server to be backed up.
  • Step 2. The local database backup and the /home/dspace folder on the production server are then copied/synced to both backup servers which use BackupPC.

Instructions

Step 1 - Production Client Server Setup

Step 2 - Individual Backup Server Setup

YouTube Video

References