Tuesday, April 25, 2006

Restoring Files From an Amanda Tape Backup

I've used the University of Maryland's open source Amanda tape backup system for some time now. There is some documentation on restoring entire disks or partitions with Amanda, but restoring individual files from tape or image file wasn't that intuitive, so I thought I'd share my experiences.

Here are the assumptions I make - it shouldn't be too hard to replace these values with your own in the synopsis below.

  • Your tape drive is on host 'backupbox' as device /dev/st0
  • Your Amanda backup set is named 'DailySet1'
  • Your tape dump files are stored on backupbox in /dumps/amanda/work/...
  • The host you are restoring data to is named 'gandalf'
  • We're restoring the file /etc/smbpasswd to host gandalf. The (Linux) partition name that this file is on is sda8

We will use amrestore (8), not the nicer amrecover (8), simply because amrestore is universal, and works even if indexes have not been generated during the backup process (i.e, if "index yes" is not set in the amanda.conf dumptype sections).

First, from a shell on backupbox, cd to the /tmp directory and rewind the most recent tape:
cd /tmp mt -f /dev/st0 rewind
Next, we use 'amadmin' to pull dump data on the partition in question. We're doing this to find out which tape to use for the restore operation. Our best bet will be the most recent level 0 (full) backup, since we just want to restore a single file. If you were restoring an entire disk or partition, you would probably need to restore the last full backup, as well as multiple, incremental backups.

backupbox:/tmp# amadmin DailySet1 find gandalf 'sda8' Scanning /dumps/amanda/work... 20060401: found Amanda directory. date host disk lv tape or file file status 2006-03-31 gandalf sda8 0 TLPC01 12 OK 2006-04-01 gandalf sda8 1 /dumps/amanda/work/20060401/gandalf.sda8.1 0 OK 2006-04-02 gandalf sda8 1 TLPC03 7 OK 2006-04-03 gandalf sda8 2 TLPC02 11 OK 2006-04-06 gandalf sda8 2 TLPC04 10 OK 2006-04-07 gandalf sda8 0 TLPC05 12 OK ... backupbox:/tmp# amadmin DailySet1 info gandalf 'sda8' Current info for gandalf sda8: Stats: dump rates (kps), Full: 495.0, 734.0, 740.0 Incremental: 479.0, 205.0, 302.0 compressed size, Full: 17.9%, 21.3%, 21.4% Incremental: 22.9%, 10.3%, 11.9% Dumps: lev datestmp tape file origK compK secs 0 20060407 TLPC05 12 10709970 1920768 3877 ...
Now we put proper tape in the tape drive and rewind again. We'll use tape TLPC05, as it's the most recent full backup.

mt -f /dev/st0 rewind amrestore -p /dev/nst0 gandalf sda8 | restore -i -v -b 2 -f -
Note that for the amrestore command, we use the "non-rewinding" version if our tape device, /dev/nst0. This will dump us into an interactive restore mode. here are some of the commands we can use the from within the restore shell:

add [path]Adds files or directories to an extraction queue
ls, cdShow a directory listing or change directories, works as expected
extractExtracts queued files (including the leading path) to the current directory

We'll see some of these commands in action now as we go over how to use an Amanda dump file with amrestore.

In the output above, we saw that the file /dumps/amanda/work/20060401/gandalf.sda8.1 was available as a level-1 backup, but had not been dumped to tape yet. This happens from time to time if there is a tape error of some sort, or the admin forgets to switch tapes. Amrestore works just as well with these files as it does with tape devices. The command to use is this: amrestore -p /dumps/amanda/work/20060401/gandalf.sda8.1 | restore -i -v -b 2 -f -
Here is what our session looks like as we restore /etc/smbpasswd from this file:

amrestore: 0: restoring gandalf.sda8.20060401.1 Verify tape and initialize maps Input is from file/pipe Input block size is 2 Dump date: Thu Apr 1 01:28:06 2006 Dumped from: Tue Mar 30 00:51:29 2006 Level 1 dump of / on gandalf:/dev/sda8 Label: none Extract directories from tape Initialize symbol table. restore > cd etc/samba restore > add smbpasswd Make node ./etc Make node ./etc/samba restore > extract Extract requested files restoring ./etc/samba/smbpasswd extract file ./etc/samba/smbpasswd Add links Set directory mode, owner, and times. set owner/mode for '.'? [yn] n restore > quit backupbox:/tmp# ls -lR etc/ etc/: total 4 drwxr-xr-x 2 root root 4096 Jul 7 12:37 samba etc/samba: total 12 -rw------- 1 root root 10622 Aug 18 16:13 smbpasswd backupbox:/tmp#
That's it. Amrestore has now copied the smbpasswd file into the /tmp/etc/samba directory for us. Now we would just have to copy the restored file over to the host gandalf.

Technorati Tags: , ,


Ashok said...

ry nice, but some commands are not fully visible as they drift out of the column and are then not visible.

Doug said...

Thanks - I"ve noticed the text problem, it shows most when the font size is large, or your screen width is relatively small. You can see the text if you highlight it with the mouse, or adjust the font size in your browser (crtl-minus in firefox).