Thursday, May 10, 2007

Restore using mtx tar cat and grep

Quick and dirty,.... you have a taperobot and you would like to restore some things from the tar backup to you local file system.

The first step is to load the tape where the backup is located. To do so we have to give the tape robot the order to get the tape out of the slot and put it into the correct tapedrive. To do so we make use of mtx which can be used to control SCSI media changer devices.

pmeflr01 tape0 # mtx -f /dev/changer load 10 0

Where /dev/changer is the scsi location of the media changer, 10 is number of the disc and 0 is the number of the target tapedrive.

Now we have the correct tape in the tapedrive and we go to the location of the tapedrive in /dev/tapes/tape0 where we find “mt”.

pmeflr01 tape0 # ls -rtl
total 0
crw-rw-rw- 1 root root 9, 128 Jan 1 1970 mtn
crw-rw-rw- 1 root root 9, 192 Jan 1 1970 mtmn
crw-rw-rw- 1 root root 9, 64 Jan 1 1970 mtm
crw-rw-rw- 1 root root 9, 160 Jan 1 1970 mtln
crw-rw-rw- 1 root root 9, 32 Jan 1 1970 mtl
crw-rw-rw- 1 root root 9, 224 Jan 1 1970 mtan
crw-rw-rw- 1 root root 9, 96 Jan 1 1970 mta
cr-xr-xr-x 1 root root 9, 0 Jan 1 1970 mt
crw-r----- 1 root root 21, 7 Jan 1 1970 generic
pmeflr01 tape0 #

because we like to know what is on the tape and we like to have a list so we can later find all the files we like to restore we generate a list of all the items in the tar.

pmeflr01 tape0 # tar -tzf mt > /tmp/johan_restore

This will generate a file named johan_restore in /tmp which contains the complete index of all the files in the tar on the tape. We can now use cat and grep to pipe only the files we like to restore to a new file. For example if we only would like to have the files in /shares0/project-01 we execute the following command to generate a new file named johan_restore_grep in /tmp

pmeflr01 tape0 # cat /tmp/johan_restore | grep /shares0/project-01 > /tmp/johan_restore_grep

having this file we can now use this as a “restore index” in tar. The –T option with the tar command gives you the option to specify a file containing all the files that should be extracted. We issue the following command to restore all the data to /shares0/temprestore so we can review the restored data before we place it back to the original location on the file system and inform the users that the data is restored.

pmeflr01 tape0 # tar -xzf mt -v -T /tmp/johan_restore_grep -C /shares0/temprestore/

After this we will have a complete restore of the data in /shares0/temprestore, first check if everything is there and if that is the case move it to the original location and inform the users.

No comments: