Sample Chapter from the Book

Basics of Backup

Backing up system and data files is a vital function of system administration. To minimize the chance of a complete data loss, backups are performed and backup media is stored at an alternate, secure location geographically separated from the system. The alternate location may be another room, building, city or another site.
In order to save valuable system data on external media, a backupstrategy needs to be developed. A backup strategy is based on several factors. The following sub-sections highlight backup and restore functions, and some critical backup strategy components.

Backup, Archive, Restore and Recovery Functions

Backup is a function of duplicating files and directories on a hard disk to an alternate media for extended storage, emergency and safety purposes. The alternate media could be a tape, a LUN in a storage system, a re-writeable optical disc or a hard drive on a remote system. Backups are typically meant to be recycled and over-written with updated data.
Archive is a function which is similar to backup, but the backed up data is intended to be kept for an extended period of time for historical purposes without being recycled or over-written. Archives may be made on tapes or write-once-read-many (WORM) discs. It is common in the IT industry to use the same alternate media for archiving purposes as is used for backups. Throughout this book the terms backup and archive are used interchangeably.
Restore is the opposite function of backup. Restore retrieves files or directories from the alternate media and places them back to where they are supposed to be on the hard disk.
A similar function called recovery recovers a crashed system to its previous normal state. It may require restoring lost data files from alternate media.

Types of Backup

There are three common types of backup performed. These are referred to as full, incremental and differential.
A full backup copies all selected files and directories and, therefore, it is self-contained. This type of backup normally takes more time to complete than other backup methods, and is usually scheduled to occur every week and once every month.
An incremental backup copies only those files that have been modified since their last full, incremental or differential backup was done. This type of backup usually takes the least amount of time to complete. An incremental backup is usually scheduled to happen on a daily basis.
A differential backup copies only those files that have been modified since they were last backed up as part of a full backup. This type of backup normally takes more time to finish than an incremental backup. A differential backup may be scheduled to occur on a daily basis in place of an incremental backup, or on a weekly basis in place of a full backup. In the latter situation, full backups are then scheduled to run once per month.

Levels of Backup

There are certain pre-defined backup levels that can be used for backups. In fact, employing these levels make backups full, incremental or differential. These levels are relative to one another. There are 10 supported levels as listed in Table 18-1.

Backup Level

Description

0

Corresponds to a full backup of selected files and directories. This is the default level.

1

Corresponds to an incremental or differential backup since the last level 0 backup occurred.

2

Represents an incremental backup since the last level 1 backup was performed and corresponds to a differential backup since the last level 0 backup occurred.

3

Represents an incremental backup since the last level 2 backup was performed and corresponds to a differential backup since the last level 0 backup occurred.

4

Represents an incremental backup since the last level 3 backup was performed and corresponds to a differential backup since the last level 0 backup occurred.

5 – 9

Follow the same rule as above for all subsequent backup levels.

Table 18-1 Backup Levels

Sample Backup Schedule

The following example explores setting up a backup schedule for a file system /opt/oracle with the following scheduling requirements:

  1. A monthly full backup on the first Sunday of each month.
  2. A weekly differential backup on each Sunday, other than the first Sunday of each month.
  3. A daily incremental backup, except on Sundays, to backup all files and directories that have changed since their last incremental or differential backup, whichever is more recent.

To develop a backup schedule to meet the above requirements, you can use level 0 to represent the full backup, level 1 to correspond to differential backups and level 2 to represent incremental backups. The following displays the schedule for five weeks to accomplish above requirements:

Date:   1 2 3 4  5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1  2  3 4 5 6
Day:    s m t w  t f  s s m  t   w   t    f    s   s   m   t   w   t   f    s   s   m   t   w   t    f    s   s  m  t  w  t  f  s s
Level: 0  2 2 2 2 2 2 1 2   2  2   2    2   2   1   2   2   2   2   2  2   1   2    2   2   2   2   2   1  2   2  2  2 2 2 0

Restore Procedure for the Sample Backup

From restore perspective, if the data becomes corrupted on Wednesday the 18th before the Wednesday backup is commenced, you will need to perform restores in the following sequence to get the data back to the Tuesday the 17th state:

  • Restore the full backup from Sunday the 1st.
  • Restore the differential backup from Sunday the 15th.
  • Restore the incremental backup from Monday the 16th.
  • Restore the incremental backup from Tuesday the 17th.

This will bring the data in /opt/oracle file system to the state where it was on Tuesday the 17th.

Managing Backups and Restores

There are many tools available in HP-UX that can be utilized to do backups and restores of files and directories. These tools include pax, fbackup/frecover, dump/restore, vxdump/vxrestore, tar, cpio, ftio and dd. The following sub-sections discuss them in detail.

Performing Backups Using pax

The pax (portable archive exchange) command archives, lists and extracts files to and from disk or tape. This command is very powerful and is compatible with cpio and tar commands in that it can list and restore archives created using them. The pax command supports both legacy and persistent tape DSFs.
Certain switches used with pax are summarized in Table 18-2.

Switch

Definition

–a

Appends to an archive.

–f

Specifies backup destination.

–r

Reads an archive.

–v

Verbose output.

–w

Writes to the specified location.

–x

Specifies cpio, pax or tar format.

Table 18-2 pax Command Options
The pax command has four modes of operation – write, list, read and copy – and are summarized in Table 18-3.

Switch

Definition

write

Writes to the destination using –w option.

list

Lists backup contents without using –r or –w options.

read

Extracts backup contents using –r option.

copy

Copies to alternate destination using both –r and –w options.

Table 18-3 pax Command Operating Modes
The following examples explain how pax works.
To write the contents of /etc directory to the tape device at /dev/rtape/tape1_BEST:
# pax –vwf /dev/rtape/tape1_BEST /etc
/etc/
/etc/fstab
/etc/opt/
/etc/opt/swm/
/etc/opt/swm/swm.conf.template
/etc/opt/swm/swm.conf
. . . . . . . .
To list contents of the tape device at /dev/rtape/tape1_BEST:
# pax vf /dev/rtape/tape1_BEST
USTAR format archive
dr-xr-xr-x        0  bin       bin                           Apr 23 07:37           /etc/
-rw-r--r--         0  root      sys             412        Apr 22 14:35           /etc/fstab
dr-xr-xr-x        0  bin       bin                           Apr 22 16:26           /etc/opt/
dr-xr-xr-x        0  bin       bin                           Apr 22 16:21           /etc/opt/swm/
-r--r--r--           0  bin       bin           40350      Jun 11  2007           /etc/opt/swm/swm.conf.template
. . . . . . . .
To read (extract) /etc directory from the tape device:
# pax vrf /dev/rtape/tape1_BEST
USTAR format archive
/etc/
/etc/fstab
/etc/opt/
/etc/opt/swm/
/etc/opt/swm/swm.conf.template
. . . . . . . .
To copy the /etc directory into /var/tmp:
# pax –vrw /etc /var/tmp/etc
/var/tmp/etc/etc
/var/tmp/etc/etc/fstab
/var/tmp/etc/etc/opt
. . . . . . . .

Performing Backups Using fbackup

The fbackup command is the HP-UX-specific native tool for performing full, incremental and differential backups. This command is deprecated in 11i v3 and will not be available in a future HP-UX release to create archives.

Some essential options fbackup supports are listed in Table 18-4.

Option

Description

–f

Specifies the device to be used for backup. There is no default tape device for fbackup.

[ 0 – 9 ]

Defines full, incremental and differential backups.

–u

Updates /var/adm/fbackupfiles/dates file at successful completion of a backup. Information written includes start and end backup time stamps, level of backup and name of the graph file used. The /var/adm/fbackupfiles directory must be available prior to using this option.

–i

Specifies files and directories to be backed up.

–e

Specifies files and directories to be excluded.

–g

Specifies the name of a graph file that contains a list of files and directories to be included in or excluded from a backup. A graph file can be used instead of –i and –e options at the command line. Each line in a graph file begins with either an “i” for include or an “e” for exclude, followed by a file or directory name.

–I

Specifies the name of a file to write index information to.

–v

Displays verbose information.

Table 18-4 fbackup Command Options
Let us look at a few examples to understand the working of fbackup.
To perform a level 0 backup of /home directory to the tape device at /dev/rtape/tape1_BEST, and write an index of the files being backed up to /tmp/index.home:
# fbackup –f /dev/rtape/tape1_BEST –i /home –I /tmp/index.home
To perform a level 0 backup of the root directory to the tape device at /dev/rtape/tape1_BEST on the first Sunday of a month based on the graph file contents (include /, exclude /var/adm/crash and /tmp), write an entry to /var/adm/fbackupfiles/dates file and generate an index of the files in /tmp/index.full:
i /
e /var/adm/crash
e /tmp

# fbackup –f /dev/rtape/tape1_BEST –u0g graph –I /tmp/index.full
To perform an incremental backup of the files and directories the next six days (Monday to Saturday) based on the contents in the graph file mentioned above, update the /var/adm/fbackupfiles/dates file and create an index file /tmp/index.incremental:

# fbackup –f /dev/rtape/tape1_BEST –u2g graph –I /tmp/index.incremental
To perform a differential backup of the files and directories on the following Sunday based on the contents in the graph file mentioned above, update the /var/adm/fbackupfiles/dates file, use tape drive at /dev/rtape/tape2_BEST and create an index file /tmp/index.differential:

# fbackup –f /dev/rtape/tape2_BEST –u1g graph –I /tmp/index.differential
To do the same level 0 backup (from above) over the network on another machine’s tape device at /dev/rtape/tape2_BEST. Suppose the remote machine is hp02 and you are on hp01. The index file /tmp/index.full will be created on hp01.

# fbackup –f hp02:/dev/rtape/tape2_BEST –u0g graph –I /tmp/index.full

Performing Restores Using frecover

The frecover command is the HP-UX-specific native tool for performing restores done using fbackup. This command is deprecated in HP-UX 11i v3 and will not be available in a future HP-UX release. Some essential options frecover supports are listed in Table 18-5.

Option

Description

–f

Specifies the device to be used for restore. The default is /dev/rtape/tape1_BEST (or /dev/rmt/0m).

–g

Specifies the name of a graph file that contains a list of files and directories to be included in or excluded from a restore. A graph file can be used instead of –i and –e options at the command line. Each line in a graph file begins with either an “i” for include or an “e” for exclude, followed by a file or directory name.

–r

Restores an entire backup. This is default.

–x

Restores selected files and directories only.

–v

Displays verbose information.

–F

Ignores leading directories from the path names of files being restored. This will allow /usr/bin/cat to be restored in /root directory as /root/cat.

–I

Specifies the name of a file to write index information to.

Table 18-5 frecover Command Options
Let us look at a few examples to understand the working of frecover.

To restore all files from the default tape device /dev/rtape/tape1_BEST and display details:
# frecover –rv

To extract only /home from a full backup using tape device at /dev/rtape/tape2_BEST:
# frecover –f /dev/rtape/tape2_BEST –i /home –xv

To do the same restore (from above) over the network from another machine’s tape device at /dev/rtape/tape2_BEST. Suppose the remote machine is hp02 and you are on hp01.
# frecover –f hp02:/dev/rtape/tape2_BEST –rv

Performing Backups/Restores Using dump/restore

These tools function similar to the way fbackup and frecover work, but with three major differences. One, these tools work at the file system level and not on individual files and directories, two, they can backup and restore only an HFS file system, and three, they do not support persistent DSFs for tape devices. Both tools support multi-level backups, store time stamp information in /var/adm/dumpdates file and use various levels of backups described earlier in the chapter.

Let us look at a couple of examples.

To pa level 0 backup of the /data1 file system to the default tape device at /dev/rtape/tape1_BEST and update the /var/adm/dumpdates file (create this file before running the dump command):

# dump 0u /data1
  DUMP: Date of this level 0 dump: Thu Apr 17 08:57:54 2008
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping /dev/vg01/rlvol1 (/data1) to /dev/rtape/tape1_BEST
  DUMP: This is an HP long file name filesystem
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 58029 tape blocks on 1.49 tape(s).
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: DUMP: 58612 tape blocks on 1 tape(s)
  DUMP: DUMP: /dev/vg01/rlvol1 has 0 inodes with unsaved optional acl entries
  DUMP: DUMP IS DONE
  DUMP: Date of completion of this level 0 dump: Thu Apr 17 08:59:03 2008
The /var/adm/dumpdates file will contain the following information after the backup is complete:
/dev/vg01/rlvol1   0   Thu  Apr 17 08:57:54 2008

To restore the above:
# restore r


Use the same syntax to backup to or restore from a tape device connected to a remote system as was demonstrated with fbackup and frecover. Many options used with dump/restore are similar to that of fbackup/frecover. Refer to man pages on usage.

Performing Backups/Restores Using vxdump/vxrestore

These tools work identically as dump and restore, but backs up and restores only JFS file systems. The two commands also support persistent DSFs. Here are a couple of examples.
To perform a level 0 backup of the /home file system to a tape device at /dev/rtape/tape2_BEST, and update the /var/adm/dumpdates file:
# vxdump 0uf /dev/rtape/tape2_BEST /home
vxfs vxdump: Date of this level 0 dump: Thu Apr 17 09:10:21 2008
vxfs vxdump: Date of last level 0 dump: the epoch
vxfs vxdump: Dumping /dev/vg00/rlvol4 (/home) to /dev/rtape/tape2_BEST
vxfs vxdump: mapping (Pass I) [regular files]
vxfs vxdump: mapping (Pass II) [directories]
vxfs vxdump: estimated 1456 blocks (728KB).
vxfs vxdump: dumping (Pass III) [directories]
vxfs vxdump: dumping (Pass IV) [regular files]
vxfs vxdump: vxdump: 970 tape blocks on 1 volumes(s)
vxfs vxdump: level 0 dump on Thu Apr 17 09:11:03 2008
vxfs vxdump: Closing /dev/rtape/tape2_BEST
vxfs vxdump: vxdump is done

To restore the above from the same tape device:
# vxrestore r /dev/rtape/tape2_BEST

Use the same syntax to backup to and restore from a tape device connected to a remote system as was demonstrated with fbackup and frecover previously. Check man pages of vxdump and vxrestore on usage.

Using tar

The tar (tape archive)command archives, lists and extracts files to and from a single file called a tar file. A tar file can be created as a regular file on disk or tape. This command supports both legacy and persistent tape DSFs.
Certain switches used with tar are summarized in Table 18-6.

Switch

Definition

c

Creates a backup.

t

Lists backup contents.

x

Extracts from a backup.

f

Specifies backup destination.

v

Verbose mode.

Table 18-6 tar Command Options
A few examples follow to explain how tar works.
To create an archive on default tape device at /dev/rtape/tape1_BEST of the /home directory:

# tar cv /home
a /home/user1/.profile 3 blocks
a /home/user1/file20 1 blocks
a /home/user1/file2 link to /home/user1/file20
. . . . . . . .
To create a single archive file called /tmp/files.tar containing files – file1, file2, file3 and file4:
# tar cvf /tmp/files.tar file1 file2 file3 file4

To view the contents of tape in the default tape device:
# tar tv
x /home/user1/.profile, 1089 bytes, 3 tape blocks
x /home/user1/file20, 101 bytes, 1 tape blocks
x /home/user1/file2 linked to /home/user1/file20
. . . . . . . .
To view the contents of the archive file files.tar:
# tar tvf /tmp/files.tar

To restore /home directory from the default tape device:
# tar xv

To extract files from /tmp/files.tar:
# tar xvf /tmp/files.tar

Using cpio

The cpio (copy in/out) command archives, lists and extracts files to and from a tape or single file. This command supports both legacy and persistent tape DSFs.
Certain options available with cpio are summarized in Table 18-7. The cpio command requires that o, i or p option be specified.

Option

Description

o

Creates a backup.

i

Extracts from a backup.

c

Reads or writes header information in ASCII format.

t

Lists backup contents.

v

Verbose mode.

p

Reads from backup to get pathnames.

a

Resets access times of files after they are copied.

Table 18-7 cpio Command Options
Here are a few examples to understand the usage.
To archive current directory contents and copy them to the /dev/rtape/tape1_BEST tape device:
# find . | cpio –ocv > /dev/rtape/tape2_BEST
(Using tape drive with immediate report mode enabled (reel #1).)
.
lost+found
ids
user1
user1/.profile
user1/file20
user1/file2
. . . . . . . .
To archive only those files in the current directory that have changed within the last week, and copy them to a file called /tmp/mod.cpio:
# find . –mtime –7 | cpio –ocv > /tmp/mod.cpio
To list the two archive files created:
# cpio –itvc < /dev/rtape/tape1_BEST
# cpio –itvc < /tmp/mod.cpio
To restore files from /tmp/mod.cpio:
# cpio –ivc < /tmp/mod.cpio

Using ftio

The ftio (faster tape in/out) command archives, lists and extracts files to and from a tape device. This command is similar in operation to the cpio command, but is used only with tape drives. ftio is deprecated in HP-UX 11i v3 and will no longer be available in a future HP-UX release to create archives.
Here are a few examples to understand the usage.
To archive current directory contents and copy them to the /dev/rtape/tape1_BEST tape device:
# find . | ftio –ocv > /dev/rtape/tape2_BEST
To list the archive:
# cpio –itvc < /dev/rtape/tape1_BEST
To restore the archive:
# cpio –ivc < /dev/rtape/tape1_BEST

Using dd

The dd command performs a bit for bit duplication. This command is useful in some limited situations and is technically not a backup command. Here is how it works.
To duplicate everything that resides under /dev/vg00/lvol1 to /dev/vg01/lvol1:
# dd if=/dev/vg00/lvol1 of=/dev/vg01/lvol1
112373+0 records in
112372+0 records out
where: “if” stands for input file and “of” for output file.

The destination lvol1 in vg01 must be either of the same size as lvol1 in vg00 or larger. View man pages of dd on detailed usage.

HP-UNIX EXAM HPO-095
Google Book Search