backup techniques

12
Backup Techniques Objectives to illustrate practical application of backup utilities Contents using dd, a direct device access command manipulating magnetic tapes getting best of cpio working with DOS format diskettes network backups Practical to use DOS utilities Summary

Upload: krysta

Post on 07-Jan-2016

17 views

Category:

Documents


0 download

DESCRIPTION

Backup Techniques. Objectives to illustrate practical application of backup utilities Contents using dd, a direct device access command manipulating magnetic tapes getting best of cpio working with DOS format diskettes network backups Practical to use DOS utilities Summary. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Backup Techniques

Backup Techniques• Objectives

– to illustrate practical application of backup utilities

• Contents– using dd, a direct device access command

– manipulating magnetic tapes

– getting best of cpio

– working with DOS format diskettes

– network backups

• Practical– to use DOS utilities

• Summary

Page 2: Backup Techniques

Direct Device Access• Use dd to access a device directly

• Useful command parameters:of=file write to named file instead of stdout

if=file read from named file instead of stdin

bs=size specify block size (also ibs and obs)

count=n copy just n records

conv=ascii convert EBCDIC to ASCII

conv=ebcdic convert ASCII to EBCDIC

conv=ibm slightly different convert ASCII to EBCDIC

conv=swab swap every pair of bytes (big endian - little endian)

# dd if=/dev/nst0 of=/tmp/ibm.tape \bs=4095 conv=ibm,swab

# dd if=/dev/nst0 of=/tmp/ibm.tape \bs=4095 conv=ibm,swab

Page 3: Backup Techniques

Exercise - Copying a Disk• How would you copy any format floppy disk?

• Checkout Linux support for msdos mimic commandsman –k mtools

mdir

mcopy

mformat

#change disks#

#change disks#

Page 4: Backup Techniques

Using dd To Identify File Type• Imagine you are given a backup disk marked with file name

but no information about command used to create it– you are asked to restore data from that backup

– which utility will you use?

• This is where dd comes into it:

• This is much neater than trying each utility in turn to see if it works!

# dd if=/dev/fd0 count=1 of=test1read just one block from the device and store it in a file

# file test1test1: tar

# dd if=/dev/fd0 count=1 of=test1read just one block from the device and store it in a file

# file test1test1: tar

Page 5: Backup Techniques

Tape Device Names• Tape devices are kept in /dev/

– device names are usually simple numbers

• By default tapes rewind after writing– tapes are not rewound before use but after

– device names ending or beginning in n will not rewind after use

• None SVR4 systems use other conventions– SCSI tape devices begin with st and nst

– Can be accessed in modes a, l, m for dencity

– Tapes are managed by mt command

# cd /# echo "Filesystem: /etc\nDate: `date`" | dd of=/dev/nst0# find etc -print | cpio -ocv >/dev/st0# dd if=/dev/nst0# cpio -itvc </dev/st0

# cd /# echo "Filesystem: /etc\nDate: `date`" | dd of=/dev/nst0# find etc -print | cpio -ocv >/dev/st0# dd if=/dev/nst0# cpio -itvc </dev/st0

Page 6: Backup Techniques

Handling Tapes with mt• Manipulate magnetic tapes with the mt command

– specify the tape device with -f

• Useful command parameters recognised:rewind rewind to start of tape

offline rewind and take offline (drive may eject tape)

fsf n skip forward n files

bsf n skip backwards n files

eom skip to end of media

status print tape unit status information

tell tell where on tape

# cd /# mt -f /dev/st0 rewind# echo "Filesystem: /etc\nDate: `date`" | dd of=/dev/st0# find etc -print | cpio -ocv >/dev/st0# mt -f /dev/st0 rewind# mt -f /dev/st0 fsf 1# cpio -itvc </dev/nst0# mt -f /dev/st0 offline

# cd /# mt -f /dev/st0 rewind# echo "Filesystem: /etc\nDate: `date`" | dd of=/dev/st0# find etc -print | cpio -ocv >/dev/st0# mt -f /dev/st0 rewind# mt -f /dev/st0 fsf 1# cpio -itvc </dev/nst0# mt -f /dev/st0 offline

Page 7: Backup Techniques

Linux filesystem dump• Not Recommended! (linux kernel 2.4)

• The dump and restore programs are Linux equivalents to the UNIX programs of the same name. As such, many system administrators with UNIX experience may feel that dump and restore are viable candidates for a good backup program under Red Hat Linux. Unfortunately, the design of the Linux kernel has moved ahead of dump's design.

# /sbin/dump -0u -f /dev/st0 /usr/src

# restore –i rf /dev/st0

# /sbin/dump -0u -f /dev/st0 /usr/src

# restore –i rf /dev/st0

Page 8: Backup Techniques

Backup & Restore with tar• Most classic and secure of them all

– Minus, cannot backup empty directories– Operate on filesystem level– Filelocking can prevent backup of files

• Backup and restore with tar

• Use crontab to schedule backups14 15 * * 6 /bin/tar cvfz /home/usershare/school/text.tar.gz /home/ftp/pub/text/*

• Incremental backups

# tar cvf /dev/st0 /home

# cd /mnt/restored; tar xvf /dev/st0

# tar cvf /dev/st0 /home

# cd /mnt/restored; tar xvf /dev/st0

Page 9: Backup Techniques

Prepairing the Backup script1. Create the backup script backup.cron file,

touch /etc/cron.daily/backup.cron - write the script on previous page and save it as backup.cron

2. date +%d%b < /backups/last-full/myserver-full-date

3. chmod 755 /etc/cron.daily/backup.cron

NOTE!

When restoring backups it is nice to have back permissions, not only the files.

tar xpf backup.tar

Up to 38% of the backup tapes will fail!

It takes as long time as the backup took to recover!

Page 10: Backup Techniques

• Speed up backups and reduce storage using compression– use the Unix compress utility to reduce archive size

• Use dd to work with larger tapes blocks– can also use the -C option to cpio (SVR4)

• TAR is most popular backup method

• Not all tape modes might be supported

Putting Them Together

# find . -print | cpio -ocvB | \

compress | dd of=/dev/st0 bs=65536

# dd if=/dev/st0 bs=65536 | \

uncompress | cpio -itvcB

# find . -print | cpio -ocvB | \

compress | dd of=/dev/st0 bs=65536

# dd if=/dev/st0 bs=65536 | \

uncompress | cpio -itvcB

Page 11: Backup Techniques

Network Backups• Use the rsh or rexec commands to run the backups across

the network

• Use NFS or similar to mount network filesystems– data can be backed up from any filesystem including networked drives

• If using network drives be careful about backing filesystems you don't want

– use the -mount option to find to restrict the file search

# find . -print | cpio -ocvB | rsh rosies dd of=/dev/st0

# rsh rosies dd if=/dev/st0 | cpio -itvcB

# find . -print | cpio -ocvB | rsh rosies dd of=/dev/st0

# rsh rosies dd if=/dev/st0 | cpio -itvcB

# rsh mash4077 'find . -print | cpio -ocvB' | dd of=/dev/st0

# dd if=/dev/st0 | rsh mash4077 cpio -itvcB

# rsh mash4077 'find . -print | cpio -ocvB' | dd of=/dev/st0

# dd if=/dev/st0 | rsh mash4077 cpio -itvcB

Page 12: Backup Techniques

Summary• Use dd for direct device access• dd can be used to encompass and read any

format backup • Tapes can be controlled with mt command• Unix support special commands for working

with DOS format diskettes• Backup utilities can be used in conjunction

with compress command to save storage• Using combination of rsh command and

backup utilities we can perform backups over the network

• Avoid dump and restore• Use TAR or CPIO• Use script for scheduling backups