Выбрать главу

-rw-r--r-- root/root 840 2005-03-02 11:59:11 etc/gconf/1/path

drwxr-xr-x root/root 0 2006-03-20 01:33:22 etc/gconf/schemas/

...(Lines skipped)...

Since the label file /system-* is the first file on the tape, you can view the originating machine as well as the date and time of the backup by just viewing the first line of the table of contents:

# tar tvzf /dev/st0|head -1

-rw-r--r-- root/root 0 2006-07-01 01:34:24 system-bluesky.fedorabook.com

To verify that all of the files on an optical disc are readable, use find to read each file on the mounted disc:

# find /media/cdrecorder -exec cp {} /dev/null \;

Only errors will be reported.

6.3.2. How Does It Work?

The growisofs command is part of the package dvd+rw-tools , which was originally intended for use with DVD+RW media. Since the original design, it has grown to include support for all DVD media formats. It operates as a frontend to the mkisofs command, which produces a filesystem in the ISO 9660 format that is the standard for optical media, and then writes the mkisofs output to the disc burner.

ISO 9660 is unfortunately limited to eight-character filenames with a three-character extension. The Rock Ridge (RR) extension adds support for long filenames, user and group ownership, and permission mode under Linux; Joliet extensions add similar support for the Windows operating systems. Using the -JR option to growisofs causes the created disk to be compatible with both Rock Ridge and Joliet.

mkzftree makes a recursive copy of a directory structure, compressing any files that would benefit from compression during the copy process. The resulting directory structure can be passed to mkisofs with the -z option, which will cause mkisofs to create additional Rock Ridge records with information about the data compression used. These records in turn enable the kernel's filesystem layer to decompress the files on the fly when reading them from disc.

When backing up to tape, tar converts a directory structure to a continuous stream of bytes. A short header contains the pathname, ownership, permissions modes, size, and timestamps for a file, followed by the data for that file; this is repeated for each file in the archive.

The z option to tar causes it to start gzip and process all data through it. As an alternative, the j option will process the archive stream through bzip2 , which may offer better compression in some circumstances.

6.3.3. What About...

6.3.3.1. ...using LVM snapshots in a backup script?

You can simply place the appropriate vgcreate and mount commands at the start of your backup script, and umount and vgremove commands at the end of the script.

Here is a slightly fancier version of the DVD backup script, which accepts a list of vg / lv pairs and creates a compressed DVD backup. Set the LVLIST and SNAPSIZE variables to whatever values you wish to use:

#!/bin/bash

#

# backup-dvd :: backup selected directories to a compressed DVD

#

# List of the vg/lv to be backed up

LVLIST="main/home main/var"

# Amount of space to use for snapshots

SNAPSIZE="1G"

# Create timestamp file

(

rm -f /system-*

touch /system-$(hostname)

# Make directory for compressed backup tree

rm -rf /tmp/zftree

mkdir /tmp/zftree

RESULT=0

for VGLV in $LVLIST

do

 echo "========= Processing $VGLV..."

 # Get information about the vg/lv

 VG=$(echo $VGLV|cut -f1 -d/)

 LV=$(echo $VGLV|cut -f2 -d/)

 SNAPNAME="${LV}-snap"

 OLDMOUNT= \

 $(grep "^/dev/${VGLV}" /etc/fstab|tr "\t" " "|tr -s " "|cut -f2 -d" ")

 NEWMOUNT="/mnt/snap${OLDMOUNT}"

 # Create a snapshot

 lvcreate -s $VGLV --name $SNAPNAME --size $SNAPSIZE

 RESULT=$(( $? + $RESULT ))

 # Mount the snapshot

 mkdir -p $NEWMOUNT

 mount -o ro /dev/${VG}/${SNAPNAME} ${NEWMOUNT}

 RESULT=$(( $? + $RESULT ))

 # Place it in the zftree

 mkdir -p /tmp/zftree$(dirname $OLDMOUNT)

 mkzftree ${NEWMOUNT} /tmp/zftree${OLDMOUNT}

 RESULT=$(( $? + $RESULT ))

 # Unmount the snapshot

 umount $NEWMOUNT

 # Release the snapshot

 lvremove -f ${VG}/${SNAPNAME}

done

if [ "$RESULT" -eq 0 ]

then

 # Burn the DVD

 growisofs -Z /dev/dvd -RJz /tmp/zftree /system-*

 # Eject the disc

 eject

else

 echo "Skipping burn: snapshot or file compression failed."

fi

# Delete the zftree

rm -rf /tmp/zftree 2>/dev/null

) 2>&1|mail -s "Backup Log $(hostname)" backup-alert

Each LV to be backed up must have a mount point identified in /etc/fstab.

6.3.3.2. ...putting more than one backup on a tape?

The device node /dev/st0 is the default (first) tape drive on the system, configured to rewind after each use. /dev/nst0 is the same device but without the automatic rewind.

In order to position the tape, Fedora provides the mt command, described in Table 6-7 .

Table 6-7. mt tape control commands

mt command Description
mt rewind Rewinds the tape
mt fsf Forward-skips a file
mt fsf count Forward-skips count files
mt bsf Backward-skips a file
mt bsf count Backward-skips count files
mt status Displays the drive status
mt offline or mt eject Rewinds and ejects the tape (if possible)