Link to home
Start Free TrialLog in
Avatar of ryeandi
ryeandi

asked on

cron file copy to tape

hi experts,
let me start off by saying i'm fairly new to scripting so please excuse any dumb questions i might ask.  i would like to create a script that copies all the files in a date-named directory.  this script will be called on a daily basis by cron.  so, for example, i have a directory named 031022 with 152 files in it.  i'd like to append this directory, complete with files, to a tape with preceeding day's files/directories on it.  the little scripting i have done has not made reference to devices.  my first question is how do you reverence the tape drive?  can you treate it just like any directory on the hard drive?  could i for example do the following:

cd the_tape_drive
mkdir 031022
cp /home/mydirectory/* the_tape_drive/031022

i have the distinct feeling that it could not be this easy.  
i'll probably have more questions later.

thanks,
rye
Avatar of yuzh
yuzh

You can not use "cp" command to backup your file to a tape drive !

For linux, you can use, tar, cpio, dump, command to backup your files to the tape.

eg.
you can create a lable file, and put it to the tape
touch 031022
tar cf  /dev/nrmt4 031022 /home/mydirectory/
rm 031022

replace /dev/nrmt4  with the real no-rewind tape device name on your system

the tape opeartion command is "mt"
man mt
to learn more

Also have a look at:
http://www.linux-mag.com/1999-07/guru_01.html
http://oldlook.experts-exchange.com/questions/20097570/backup-to-a-tape.html
http://oldlook.experts-exchange.com/questions/20126439/Cron-and-Tar-backup-Easy-Question.html
http://oldlook.experts-exchange.com/questions/10131894/dump-2-or-more-filesystems-to-1-tape.html
http://oldlook.experts-exchange.com/questions/20662120/Full-system-Backup.html

ok, I think I understand what your are trying to do:

if you want to copy files from /home/mydirectory to /the_tape_backup-dir/031022,
then backup /the_tape_drive/031022 to tape (it cost you extra HD space!)

you can do:

cd /home/mydirectory
mkdir /the_tape_backup-dir/031022
tar cf - . | (cd /the_tape_backup-dir/031022 ; tar xf -)

tar cf /dev/nrmt4  /the_tape_backup-dir/031022

PS: you can not do mkdir to a tape device !!!!
Avatar of ryeandi

ASKER

yuzh, so basically what you're saying is create an archive of the files in the dated directory and append each to the tape?  
so basically like this?

##first date on the tape
cd /home/mydirectory/031022     #directory has already been created by another script
tar -cf 031022.tar *
tar -cf /dev/???? /home/mydirectory/031022/031022.tar

##following days until tape is full
cd /home/mydirectory/yymmdd
tar -cf yymmdd.tar *
tar -rf /dev/???? /home/mydirectory/yymmdd/yymmdd.tar
ASKER CERTIFIED SOLUTION
Avatar of yuzh
yuzh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ryeandi

ASKER

thanks for the help,  i still have a couple of questions.
i was planning on using:
mt -f /dev/???? eod   #will this work?
then:
tar -rf /dev/???? /home/mydirectory/yymmdd/yymmdd.tar

what is the reason i would need to keep an index?

also, i'm confused about the ???? in the above example.  this machine kind of fell on my lap.  there seems to be 2 removable media devices.  one is a zip drive and the other is a hp superstore dat24 tape drive.  i'm planning on doing the backups to this tape drive.  when i look at /dev i see a ton of entries.  how do i know what device file is the one that points to the driver for this drive?  

"what is the reason i would need to keep an index?"

Tape is a sequential storage device. keep an index file (text file) to, help
you locate your backup files in the tape, when you use no-rewind tape
device.

man mt
to learn more about the tape operations.

To find out the exactly tape device name, you can try

ls -al /dev/*mt*
ls -al /dev/*st*

Have a look at the following pages to learn more about tape devices:
http://www.linux-mag.com/1999-07/guru_01.html
http://www.tldp.org/HOWTO/SCSI-2.4-HOWTO/dnames.html

Good luck!

Avatar of ryeandi

ASKER

when i do a "ls -al /dev/*mt*" i get the following:  
rmt16
rmt8
when i do a "ls -al /dev/*st*" i get the following:
nst0 - nst7
st0 - st7

how do i know which one of these refers to the actual tape drive i'll be backing up to?
does it matter?
/dev/st0      \device\tape0, rewind
/dev/nst0      \device\tape0, no-rewind


Put a blank tape into the tape drive:

try:

mt -f /dev/nst0 rewind

see if any light on in the tape drive

or

mt -f /dev/st0 rewind

then try to use tar to copt some file to the tape drive

eg:
copt test dir to tape:
tar cvf /dev/nst0  testdir
rewind the tape
mt -f /dev/st0 rewind
verify what's on the tape
tar tvf /dev/nst0  
Please read the following page for the tape operations:

http://www.ociw.edu/lco/computer_info/DAT.html
Avatar of ryeandi

ASKER

thanks for all the help.  sorry about the late awarding of points.  i've been having drive troubles and was waiting to see if the above worked.  the troubles didn't get fixed but i didn't want to make you wait any longer.  thanks a lot.

rye