Navigation
  About us
  Our Portfolio
  Enquiry
  Search
  Contact Us
  Site Map
  Email Login
  Downloads
 


BACKUP & MAINTENANCE SERVICES
     

Remote backup system
 Local backup system
 Data maintenance system

The tar backup program is an archiving program designed to store and extract files from an archive file known as a tarfile. A tarfile may be made on a tape drive; however, it is also common to write a tarfile to a normal file.

A simple backup is when you decide to make a backup of files on your system you must choose a backup scheme before the beginning of your backup procedure. A lot of strategic backup schemes exist, and depend on the backup policies you want to use. In the following, we have shown you one backup scheme that you may use which takes advantage of the tar program's capabilities. This scheme is to first back up everything once, then back up everything that has been modified since the previous backup:

i. The first backup is called a full backup
ii. The subsequent ones are incremental backups.

With six tapes you can make backups every day; The procedure is to use tape 1 for the first full backup Friday 1, and tapes 2 to 5 for the incremental backups Monday through Thursday. Then, you make a new full backup on tape 6 second Friday, and start doing incremental ones with tapes 2 to 5 again. It's important to keep tape 1 at its state until you've got a new full backup with tape 6.

In the following example below, we assume that we write the backup to a SCSI tape drive named /dev/st0, and we backup the home directory /home of our system. First of all, we must to move to the file system / partition. When creating an archive file, tar will strip leading / slash characters from file path names. This means that restored files may not end up in the same locations they were backed up from. Therefore, to solve the problem, the solution is to change to the / root directory before making all backups and restorations.

It is important to always start with a full backup; say on a Friday, for example:

Friday 1: use tape 1 for the first full backup.

[root@deep] /# cd /
[root@deep] /# tar cpf /dev/st0 --label=" full-backup created on `date '+%d-%B-%Y'`." --directory / home

Monday: use tapes 2 for the incremental backups.

[root@deep] /# tar cpNf /dev/st0 --label=" full-backup created on `date '+%d-%B-%Y'`." --directory / home

Tuesday: use tapes 3 for the incremental backups.

[root@deep] /# tar cpNf /dev/st0 --label=" full-backup created on `date '+%d-%B-%Y'`." --directory / home

Wednesday: use tapes 4 for the incremental backups.

[root@deep] /# tar cpNf /dev/st0 --label=" full-backup created on `date '+%d-%B-%Y'`." --directory / home

Thursday: use tapes 5 for the incremental backups.

[root@deep] /# tar cpNf /dev/st0 --label=" full-backup created on `date '+%d-%B-%Y'`." --directory / home

Friday 2: use tape 6 for the new full backups.

[root@deep] /# tar cpf /dev/st0 --label=" full-backup created on `date '+%d-%B-%Y'`." --directory / home

Now, start doing incremental ones with tapes 2 to 5 again and so on.

The c option specifies that an archive file is begin created.

The p option preserves permissions; file protection information will be remembered.

The N option does an incremental backup and only stores files newer than DATE.

The f option states that the very next argument will be the name of the archive file or device being written.

Notice how a filename, which contains the current date, is derived, simply by enclosing the date command between two back-quote characters. A common naming convention is to add a tar suffix for non-compressed archives, and a tar.gz suffix for compressed ones. Since we aren't able to specify a filename for the backup set, the --label option can be used to write some information about the backup set into the archive file itself. Finally, only the files contained in the /home are written to the tape.

Because the tape drive is a character device, it is not possible to specify an actual file name. Therefore, the file name used as an argument to tar is simply the name of the device, /dev/st0, the first tape device. The /dev/st0 device does not rewind after the backup set is written. Therefore it is possible to write multiple sets on one tape. You may also refer to the device as /dev/st0, in which case the tape is automatically rewound after the backup set is written. When working with tapes you can use the following commands to rewind and eject your tape:

[root@deep] /# mt -f /dev/st0 rewind
[root@deep] /# mt -f /dev/st0 off-line

To reduce the space needed on a tar archive, the backups can be compressed with the z option of tar program. Unfortunately, using this option to compress backups can cause trouble. Due to the nature of how compression works, if a single bit in the compressed backup is wrong, all the rest of the compressed data will be lost. It's recommended to NOT using compression, the z option to make backups with the tar command.

If your backup doesn't fit on one tape, you'll need to use the --multi-volume -M option:

[root@deep] /# tar cMpf /dev/st0 /home

Prepare volume #2 for /dev/st0 and hit return:

After you have made a backup, you should check that it is OK, using the --compare -d option as shown below:

[root@deep] /# tar dvf /dev/st0

To perform a backup of your entire system, use the following command:

[root@deep] /# tar cpf /archive/full-backup-`date '+%d-%B-%Y'`.tar \
--directory / --exclude=proc --exclude=mnt --exclude=archive \
--exclude=cache --exclude=*/lost+found .

The --directory option tells tar to first switch to the following directory path, the / directory in this example, prior to starting the backup.

The --exclude options tells tar not to bother backing up the specified directories or files.

The . character at the end of the command tells tar that it should back up everything in the current directory.

===============

Automating backups with tar
It is always interesting to automate the tasks of a backup. Automation offers enormous opportunities for using your Linux server to achieve the goals you set. The following example below is our backup script, called backup.cron. This script is designed to run on any computer by changing only the four variables:

i.COMPUTER
ii.DIRECTORIES
iii.BACKUPDIR
iv.TIMEDIR

We suggest that you set this script up and run it at the beginning of the month for the first time, and then run it for a month before making major changes. In our example below we do the backup to a directory on the local server BACKUPDIR, but you could modify this script to do it to a tape on the local server or via an NFS mounted file system.

1.Create the backup script backup.cron file, touch /etc/cron.daily/backup.cron and add the following lines to this backup file:

#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@freebsd.org>
# and modified by Gerhard Mourani <gmourani@videotron.ca>

#Change the 5 variables below to fit your computer/backup

COMPUTER=deep # name of this computer
DIRECTORIES="/home" # directories to backup
BACKUPDIR=/backups # where to store the backups
TIMEDIR=/backups/last-full # where to store time of full backup
TAR=/bin/tar # name and location of tar

#You should not have to change anything below here

PATH=/usr/local/bin:/usr/bin:/bin
DOW=`date +%a` # Day of the week e.g. Mon
DOM=`date +%d` # Date of the Month e.g. 27
DM=`date +%d%b` # Date and Month e.g. 27Sep

# On the 1st of the month a permanet full backup is made
# Every Sunday a full backup is made - overwriting last Sundays backup
# The rest of the time an incremental backup is made. Each incremental
# backup overwrites last weeks incremental backup of the same name.
#
# if NEWER = "", then tar backs up all files in the directories
# otherwise it backs up files newer than the NEWER date. NEWER
# gets it date from the file written every Sunday.

# Monthly full backup
if [ $DOM = "01" ]; then
NEWER=""
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DM.tar $DIRECTORIES
fi

# Weekly full backup
if [ $DOW = "Sun" ]; then
NEWER=""
NOW=`date +%d-%b`

# Update full backup date
echo $NOW > $TIMEDIR/$COMPUTER-full-date
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES

# Make incremental backup - overwrite last weeks
else

# Get date of last full backup
NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`"
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES
fi

Example 33-1. Backup directory of a week

Here is an abbreviated look of the backup directory after one week:

[root@deep] /# ls -l /backups/

total 22217
-rw-r--r-- 1 root root 10731288 Feb 7 11:24 deep-01Feb.tar
-rw-r--r-- 1 root root 6879 Feb 7 11:24 deep-Fri.tar
-rw-r--r-- 1 root root 2831 Feb 7 11:24 deep-Mon.tar
-rw-r--r-- 1 root root 7924 Feb 7 11:25 deep-Sat.tar
-rw-r--r-- 1 root root 11923013 Feb 7 11:24 deep-Sun.tar
-rw-r--r-- 1 root root 5643 Feb 7 11:25 deep-Thu.tar
-rw-r--r-- 1 root root 3152 Feb 7 11:25 deep-Tue.tar
-rw-r--r-- 1 root root 4567 Feb 7 11:25 deep-Wed.tar
drwxr-xr-x 2 root root 1024 Feb 7 11:20 last-full

: The directory where to store the backups BACKUPDIR, and the directory where to store time of full backup TIMEDIR must exist or be created before the use of the backup-script, or you will receive an error
message.

2.If you are not running this backup script from the beginning of the month 01-month-year, the incremental backups will need the time of the Sunday backup to be able to work properly. If you start in the middle of the week, you
will need to create the time file in the TIMEDIR. To create the time file in the TIMEDIR directory, use the following command:

[root@deep] /# date +%d%b < /backups/last-full/myserver-full-date

Where /backups/last-full is our variable TIMEDIR wherein we want to store the time of the full backup, and myserver-full-date is the name of our server e.g. deep, and our time file consists of a single line with the
present date i.e. 15-Feb.

3.Make this script executable and change its default permissions to be writable only by the super-user root 755:

[root@deep] /# chmod 755 /etc/cron.daily/backup.cron

Because this script is in the /etc/cron.daily directory, it will be automatically run as a cron job at one o'clock in the morning every day.

================

Restore files with tar
More important than performing regular backups is having them available when we need to recover important files! In this section, we will discuss methods for restoring files, which have been backed up with tar command.

The following command will restore all files from the full-backup-Day-Month-Year.tar archive, which is an example backup of our home directory created from the example tar commands shown above.

[root@deep] /# tar xpf /dev/st0/full-backup-Day-Month-Year.tar

The above command extracts all files contained in the compressed archive, preserving original file ownership and permissions.

The x option stands for extract.

The p option preserve permissions; file protection information will be remembered.

The f option states that the very next argument will be the name of the archive file or device.

If you do not need to restore all the files contained in the archive, you can specify one or more files that you wish to restore: To specify one or more files that you wish to restore, use the following command:

[root@deep]# tar xpf /dev/st0/full-backup-Day-Month-Year.tar \
home/wahib/Personal/Contents.doc home/quota.user

The above command restores the /home/wahib/Personal/Contents.doc and /home/quota.user files from the archive.

If you just want to see what files are in the backup volume, Use the --list or -t option:

[root@deep] /# tar tf /dev/st0

If you have files on your system set with the immutable bit, using the chattr command, these files will not be remembered with the immutable bit from your restored backup. You must reset it immutable with the command chattr +i after the backup is completed.

Test the ability to recover: Don't forget to test the ability to recover from backups, for many system administrators, recovering a file from a backup is an uncommon activity. This step assures that if you need to recover a file, the tools and processes will work. Performing this test periodically will help you to discover problems with the backup procedures so you can correct them before losing data. Some backup restoration software does not accurately recover the correct file protection and file ownership controls. Check the attributes of restored files to ensure they are being set correctly. Periodically test to ensure that you can perform a full system recovery from your backups.