Total Pageviews

Wednesday, November 10, 2010

Backup Users Home Directory

Depending on your bandwidth, the size of the directory and the location of the remote server, it can take an awful lot of time to make backups using this mechanism. For larger directories and lower bandwidth, use rsync to keep the directories at both ends synchronized.
users-home-backup.sh

#!/bin/sh
#set -x
##This is my first script to backup a users home folder on to remote server
# Change the values of the variables to make the script work for you:
BACKUPDIR=/home
BACKUPFILES=paps
TARFILE=/var/tmp/home_paps.tar
BZIPFILE=/var/tmp/home_paps.tar.bz2
SERVER=iscsibackup.example.com
REMOTEDIR=/backup-disk1/paps/backups
LOGFILE=/var/tmp/paps_backup.log


cd $BACKUPDIR

# This creates the archive
tar cf $TARFILE $BACKUPFILES > /dev/null 2>&1

# First remove the old bzip2 file.  Redirect errors because this generates some if the archive
# does not exist.  Then create a new compressed file.
rm $BZIPFILE 2> /dev/null
bzip2 $TARFILE

# Copy the file to another host - we have ssh keys for making this work without intervention.
scp $BZIPFILE root@$SERVER:$REMOTEDIR > /dev/null 2>&1

# Create a timestamp in a logfile.
date >> $LOGFILE
echo backup succeeded >> $LOGFILE

No comments: