|
Can this help you???
How to use your Tapedrive
Several of our Linux workstations are equiped with a tape drive. Tapes are normally used to exchange data, for backups Netbackup is the preferred solution. See How to install Netbackup.
• Devices
• Samples with tar
• Multiple files on the same tape
• Backup across multiple tapes
• Using cpio
• find the content of a tape
________________________________________
All tapedrives are attached over a SCSI-controller. To access a tape, choose the right devicenode:
• /dev/st0 Linux 2.2 / D-PHYS1, first tapedrive, rewinds when closed
• /dev/nst0 Linux 2.2 / D-PHYS1, first tapedrive, leaves tape when closed
Currently all machines equiped with a tapedrive are running Linux 2.2. Come back to this tutorial after our upgrade of those workstations!
To save and restore data on tape, we use tar, mt and cpio. dump is not discussed here - it should not be used in Linux >= 2.4 against a mounted filesystem.
________________________________________
Now put a fresh cartdrige of the right type in your tapedrive and go through this tutorial:
check if the tape is online
me@host:~$ mt -f /dev/st0 status
drive type = Generic SCSI-2 tape
drive status = 318767104
sense key error = 0
residue count = 0
file number = 0
block number = 0
Tape block size 0 bytes. Density code 0x13 (DDS (61000 bpi)).
Soft error count since last status=0
General status bits on (45010000):
BOT WR_PROT ONLINE IM_REP_EN
A cartdrige is inserted and ready to write. Because we used /dev/st0, the tape is now positioned at the beginning.
save the content of a directory
We have a directory sample in our home containing several files. Lets put them on the tape:
me@host:~$ tar cvf /dev/st0 sample
sample/
sample/picture.jpeg
sample/text.txt
sample/source.c
list the files on the tape
me@host:~$ tar tvf /dev/st0
drwxr-xr-x me/mygroup 0 2003-10-31 12:54:22 sample/
-rw------- me/mygroup 54864 2003-10-31 12:53:56 sample/picture.jpeg
-rw-r--r-- me/mygroup 1297 2003-10-31 12:54:03 sample/text.txt
-rw-r--r-- me/mygroup 58 2003-10-31 12:54:22 sample/source.c
eject the cartdrige
me@host:~$ mt -f /dev/st0 rewoffl
The cartdrige will be rewinded and ejected by the tapedrive. It's now time to lable your cartdrige. It's really difficult to extract the information about a tape without knownlege how it was written! May be that it's also the time to write protect the cartdrige.
restore the files
Reinsert the cartdrige in the tapedrive.
me@host:~$ tar xvf /dev/st0
sample/
sample/picture.jpeg
sample/text.txt
sample/source.c
We have now restored the content of the archive on tape.
restore a single file
me@host:~$ tar xvf /dev/st0 sample/source.c
sample/source.c
Only the file source.c was restored. Be careful - you need to give the exact filname(s) to tar and it takes often a long time to scan the tape until tar find the right file.
________________________________________
Now some more sophisticated exemples. A cartdrige may contain more then one file. So you may put more then one backup on the same cartdrige. Now we use no longer /dev/st0 which rewinds the tape after usage, instead we use /dev/nst0 which leaves the tape on the position when closed.
check if the tape is online
me@host:~$ mt -f /dev/st0 status
drive type = Generic SCSI-2 tape
drive status = 318767104
sense key error = 0
residue count = 0
file number = 0
block number = 0
Tape block size 0 bytes. Density code 0x13 (DDS (61000 bpi)).
Soft error count since last status=0
General status bits on (45010000):
BOT WR_PROT ONLINE IM_REP_EN
save a directory
me@host:~$ tar cvf /dev/nst0 sample
sample/
sample/picture.jpeg
sample/text.txt
sample/source.c
This is now our first file on the tape. Because we used /dev/nst0, tape is now positioned at the end of this file.
save another directory
me@host:~$ tar cvf /dev/nst0 moresample
moresample/
moresample/source.c
moresample/binary
This is now our second file on the tape.
eject the cartdrige
me@host:~$ mt -f /dev/st0 rewoffl
Now it's the time to lable the cartdrige. There is now way to "see" how many files are on a tape.
restore the files
Restore from the first backup is simple. But we restore now the files from the second :-)
me@host:~$ mt -f /dev/nst0 fsf 1
me@host:~$ tar xvf /dev/nst0
moresample/
moresample/source.c
moresample/binary
me@host:~$ mt -f /dev/nst0 rewind
First we forward the tape to the second file. Then we restore the data and at the end we rewind the tape. See the manpage of mt for all options how to forward / rewind a tape.
________________________________________
Often, a cartdrige is too small to hold all the data you want to save. tar knows about "multivolume" with the command line option -M and will prompt you for the next tape:
me@host:~$ tar cvfM /dev/st0 bigdir
bigdir/
bigdir/ae
bigdir/arch
bigdir/ash
...
Prepare volume #2 for `/dev/st0' and hit return:
bigdir/ln
bigdir/loadkeys
...
To list or restore such an archive, you need to give tar the option -M. So be sure to lable the cartdrige.
________________________________________
Some people prefer to write their backups with cpio. I don't. cpio is a very feature rich command, on the other hand I always need the manpage when I want to create or expand an archive. cpio expects a filelist on STDIN and creates the archive on STDOUT or expects the archive for restoring on STDIN. To save data with cpio, you allways need find to create the filelist.
save the content of a directory
me@host:~$ find sample | cpio -ov -H newc > /dev/st0
sample
sample/picture.jpeg
sample/text.txt
sample/source.c
112 blocks
list the files on the tape
me@host:~$ cpio -itv < /dev/st0
drwxr-xr-x me/mygroup 0 2003-10-31 12:54:22 sample/
-rw------- me/mygroup 54864 2003-10-31 12:53:56 sample/picture.jpeg
-rw-r--r-- me/mygroup 1297 2003-10-31 12:54:03 sample/text.txt
-rw-r--r-- me/mygroup 58 2003-10-31 12:54:22 sample/source.c
restore the files
me@host:~$ cpio -ivd < /dev/st0
sample
sample/picture.jpeg
sample/text.txt
sample/source.c
112 blocks
See the manpage of cpio for all options.
For the last time: lable the cartdrige because the format of cpio and tar are not compatible.
________________________________________
Now worst case. You have an unlabeled cartdrige in front of you and you don't know which data is on it. There are some tricks to find it out. Insert the cartdrige and find out the type of archive on it:
me@host:~$ file - < /dev/nst0
standard input: GNU tar archive
The first file on this tape is a tar archive.
me@host:~$ mt -f /dev/nst0 fsf 1
Forward tape to the next file.
me@host:~$ file - < /dev/nst0
standard input: POSIX tar archive
The second file is also a tar archive - but it seems to be created on a UNIX like Solaris.
me@host:~$ mt -f /dev/nst0 fsf 1
Forward tape to the next file.
me@host:~$ file - < /dev/nst0
standard input: ASCII cpio archive (SVR4 with no CRC)
The third file on this tape is a cpio archive.
me@host:~$ mt -f /dev/nst0 fsf 1
Forward tape to the next file.
me@host:~$ file - < /dev/nst0
standard input: file: read failed (Input/output error).
OK, it's the end of the tape.
me@host:~$ mt -f /dev/nst0 rewind
Now we write down our seen files:
1 GNU tar archive
2 Posix tar archive
3 cpio archive
To see the content of each file on the tape, we use now the approriate command to extract the archives:
me@host:~$ tar tvf /dev/nst0
...
me@host:~$ tar tvf /dev/nst0
...
me@host:~$ cpio -itv < /dev/st0
...
After that, you are able to lable the cartdrige :-)
|