It's a kind of magic.

Restore Amanda Backup

I'm writing this blogpost so I can quickly find the needed commands to restore a file from an amanda backup. Below is a procedure on how to extract the LocalSettings.php file. The /data/amanda/tapes is the directory where the virtual tapes are located. The host is backup, amanda org is Daily.

[root@backup backup]# amrecover Daily -s backup -t backup \
-d file:/data/amanda/tapes
AMRECOVER Version 2.5.0p2. Contacting server on backup ...
220 backup AMANDA index server (2.5.0p2) ready.
200 Access OK
Setting restore date to today (2009-12-02)
200 Working date set to 2009-12-02.
Scanning /data/amanda/holding...
200 Config set to Daily.
200 Dump host set to backup.vsco.be.
Trying disk / ...
Trying disk rootfs ...
Can't determine disk and mount point from $CWD '/backup'
amrecover>

ok now we can start by specifying which file is needed to restore.

amrecover> sethost web.vsco.be
200 Dump host set to web.vsco.be.

First the disk (you can view all disks with the command listdisk):

amrecover> setdisk /data
200 Disk set to /data.

amrecover> setdate 2009-11-30
200 Working date set to 2009-11-30.

amrecover> ls
2009-11-30 www/
2009-11-30 lost+found/
2009-11-30 home/

amrecover> cd www/wiki
/backup/data/www/wiki

Now add the file/files you want to restore (wildcars can be used)

amrecover> add LocalSettings.php
Added /www/wiki/LocalSettings.php

amrecover> extract

Extracting files using tape drive null: on host backup.
The following tapes are needed: Daily-005

Restoring files into directory /backup
Continue [?/Y/n]? Y

Extracting files using tape drive null: on host backup.
Load tape Daily-005 now
Continue [?/Y/n/s/t]?

Now we have to mount the correct tape, either by changing the soft link in /backup/amanda/tapes/

Or with the amtape command, do this in another shell, and keep your amrecover shell open:

[root@backup backup]# su - amanda
-bash-3.2$ amtape Daily current
changer: got exit: 0 str: 14 18 1
changer_query: changer return was 18 1
changer_query: searchable = 0
amtape: scanning current slot in tape-changer rack:
changer: got exit: 0 str: 14 file:/data/amanda/tapes
slot 14: date 20091202 label Daily-014

We can see we are currently on slot 14 which contains tape Daily-014

-bash-3.2$ amtape Daily show
changer: got exit: 0 str: 14 18 1
changer_query: changer return was 18 1
changer_query: searchable = 0
amtape: scanning all 18 slots in tape-changer rack:
changer_find: looking for NULL changer is searchable = 0
changer: got exit: 0 str: 14 file:/data/amanda/tapes
slot 14: date 20091202 label Daily-014
changer: got exit: 0 str: 15 file:/data/amanda/tapes
slot 15: not an amanda tape (Read 0 bytes)
changer: got exit: 0 str: 16 file:/data/amanda/tapes
slot 16: not an amanda tape (Read 0 bytes)
changer: got exit: 0 str: 17 file:/data/amanda/tapes
slot 17: not an amanda tape (Read 0 bytes)
changer: got exit: 0 str: 18 file:/data/amanda/tapes
slot 18: not an amanda tape (Read 0 bytes)
changer: got exit: 0 str: 1 file:/data/amanda/tapes
slot 1: date 20091119 label Daily-001
changer: got exit: 0 str: 2 file:/data/amanda/tapes
slot 2: date 20091120 label Daily-002
changer: got exit: 0 str: 3 file:/data/amanda/tapes
slot 3: date 20091121 label Daily-003
changer: got exit: 0 str: 4 file:/data/amanda/tapes
slot 4: date 20091122 label Daily-004
changer: got exit: 0 str: 5 file:/data/amanda/tapes
slot 5: date 20091123 label Daily-005
changer: got exit: 0 str: 6 file:/data/amanda/tapes
slot 6: date 20091124 label Daily-006
changer: got exit: 0 str: 7 file:/data/amanda/tapes
slot 7: date 20091125 label Daily-007
changer: got exit: 0 str: 8 file:/data/amanda/tapes
slot 8: date 20091126 label Daily-008
changer: got exit: 0 str: 9 file:/data/amanda/tapes
slot 9: date 20091127 label Daily-009
changer: got exit: 0 str: 10 file:/data/amanda/tapes
slot 10: date 20091128 label Daily-010
changer: got exit: 0 str: 11 file:/data/amanda/tapes
slot 11: date 20091129 label Daily-011
changer: got exit: 0 str: 12 file:/data/amanda/tapes
slot 12: date 20091130 label Daily-012
changer: got exit: 0 str: 13 file:/data/amanda/tapes
slot 13: date 20091201 label Daily-013

We need the tape in slot 5

-bash-3.2$ amtape Daily slot 5
changer: got exit: 0 str: 5 file:/data/amanda/tapes
amtape: changed to slot 5 on file:/data/amanda/tapes
-bash-3.2$ amtape Daily current
changer: got exit: 0 str: 5 18 1
changer_query: changer return was 18 1
changer_query: searchable = 0
amtape: scanning current slot in tape-changer rack:
changer: got exit: 0 str: 5 file:/data/amanda/tapes
slot 5: date 20091123 label Daily-005

Ok now we can continue our extract in the amrecover shell.

amrecover> extract

Extracting files using tape drive file:/data/amanda/tapes on host backup.
The following tapes are needed: Daily-005

Restoring files into directory /backup
Continue [?/Y/n]?

Extracting files using tape drive file:/data/amanda/tapes on host backup.
Load tape Daily-005 now
Continue [?/Y/n/s/t]?
./www/wiki/LocalSettings.php
amrecover> exit

[root@backup backup]# ls -al ./www/wiki/LocalSettings.php
-r-------- 1 48 48 5220 Nov 6 11:15 ./www/wiki/LocalSettings.php