Backup software

mt

The mt command can be used to control the magnetic tape device attached to your Debian machine.

SYNTAX:
mt <command>
                

A list of valid commands are:

Table 4.1. mt commands

eof, weof Write count EOF marks at current position.
fsf Forward space count files. The tape is positioned on the first block of the next file.
bsf Backward space count files. The tape is positioned on the first block of the next file.
fsr Forward space count records.
bsr Backward space count records.
bsfm Backward space count file marks. The tape is positioned on the beginning-of-the-tape side of the file mark
fsfm Forward space count file marks. The tape is positioned on the beginning-of-the-tape side of the file mark.
rewind Rewind the tape.
offline, rewoffl Rewind the tape and, if applicable, unload the tape.
status Print status information about the tape unit.
erase Erase the tape.

When using a tape stream to make backups onto, you will need to set EOF marks (using the weof command) between each backup session on the tape, so that you can easily seek between them. You can then use the fsf and bsf commands to seek through the tape to the various positions for each backup. In order to make the tape drive eject the current tape, you should issue the offline command.

tar

The "tape archiver", or tar command is one that you should be familiar with already. This can form the staple part of your backup strategy. This can be used to users to make backups of their own files, or by the system administrator to make backups of entire filesystems.

SYNTAX:
tar [c | x | t ] [z ] [ v ] [ -f filename ] [ files ... ]

  c  create an archive
  x  extract from an archive
  t   test an archive

  z   compress/uncompress the archive using gzip

  v   be verbose

  -f  filename  -- this specifies which archive or device to use.
                

The "files ..." is a matching path for the files and/or directories that you wish to archive or extract.

Examples:

To archive your /usr directory into a file called /backups/usr.tar.gz, and compress it, you would use:

debian:/# tar czf /backups/usr.tar.gz usr
debian:/# _
                    

To verify that the archive you created:

debian:/# tar tzf /backups/usr.tar.gz
usr/
usr/bin/
usr/bin/whiptail
[ ... ]
                    

If you add the verbose ("v") switch, you'll even be given a long directory listing:

debian:/# tar tzvf /backups/usr.tar.gz
drwxr-xr-x root/root         0 2004-03-12 15:40:28 usr/
drwxr-xr-x root/root         0 2004-03-25 23:18:34 usr/bin/
-rwxr-xr-x root/root     15936 2002-03-31 03:00:42 usr/bin/whiptail
[ ... ]
                    

If we wanted to extract the files into a new directory, we could do something like this:

debian:/# mkdir newusr
debian:/# cd newusr
debian:/newusr# tar xzf /backups/usr.tar.gz
                    

cpio

The "CoPy In/Out", or cpio command is very similar to tar in functionality.

Unfortunately, cpio is not as intuitive to use as tar, but it can handle backing up and restoring device files (those in /dev), which tar cannot.

For an example, we will back up our /dev directory:

debian:~# find /dev -print | cpio -o > backup.cpio
debian:~# ls backup.cpio 
backup.cpio
                

We pass cpio a list of files that we want backed up, from the find command, via standard input. The "-o" flag tells cpio that we wish to create a backup archive. We then redirect the output from cpio to a file called "backup.cpio". We could also have directed this output to a tape device if we wanted the backup to go directly to tape.

In order to restore files from a cpio archive, we use the "-i" flags. Let's test restoring our /dev/null device back to where it should be after we delete it:

debian:~# ls /dev/null 
/dev/null
debian:~# rm /dev/null 
debian:~# ls /dev/null 
ls: /dev/null: No such file or directory
debian:~# cpio -i /dev/null < backup.cpio 
414 blocks
debian:~# ls /dev/null 
/dev/null
debian:~# cpio -i /dev/null < backup.cpio 
cpio: /dev/null not created: newer or same age version exists
414 blocks
debian:~# _
                

You'll notice that cpio won't let us overwrite an already existing file if it is newer or the same age as the one in the archive.

The "-i" flags takes a pattern as a parameter; the pattern should match the file(s) that you wish to have restored. In the example above, we only wanted the /dev/null file restored

dump and restore

The dump and restore commands, which originated from 4.4BSD, will do a dump (backup) and restore of an ext2 filesystem, respectively. Dump understands the concept of "dump levels", as discussed previously. However, this mode only works on complete filesystems.

Debian doesn't come with these commands by default, so you'll have to install the dump package if you wish to use them:

debian:~# apt-get install dump
                
SYNTAX: dump [-0 ... -9 ] [-u] -f <target> <filesystem>
                

The numeric options specify the dump level, the "target" is the destination file or device where you wish to send the backup to, and the "filesystem" is the one you wish to back up. The "-u" options tells dump to record the date and time of the dump, so that you can check later when the last backup was done. You can use the "-W" switch to check this later.

To do a full (level 0) backup of our root ("/") partition onto tape (/dev/st0), we would issue a command similar to:

dump -0u -f /dev/st0 /
                

And then to check and see when the last time a dump was done:

dump -W
                

The package comes with a lot of useful examples and documentation, which you should definitely take a look through. Remember, you can ask dpkg to give you a list of all the files associated with a specific package:

dpkg --listfiles dump
                

dd

The dd command can be useful for transferring backups to and from tape and other media.

For example, to send a .tar.gz backup that we'd made earlier to a tape drive, we could issue a command similar to:

dd if=backup.tar.gz of=/dev/nrsa0