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
LVL 1
ryeandiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yuzhCommented:
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/Databases/Sybase/Q_20097570.html
http://oldlook.experts-exchange.com/Networking/Linux_Networking/Q_20126439.html
http://oldlook.experts-exchange.com/Operating_Systems/Unix/Q_10131894.html
http://oldlook.experts-exchange.com/Operating_Systems/Linux/Q_20662120.html

0
yuzhCommented:
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 !!!!
0
ryeandiAuthor Commented:
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
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

yuzhCommented:
You are on the right track, why do you want to create anther tar ball 031022.tar, it does n't save any space? (you can do it if you want to).

You need to maintain a tape index file soemwhere to track the backup file
position.

eg.
date            index
031022        0
031023        1
031024        2

when the tape is full, use:
mt -f /dev/??? rewind

use:
mt -f /dev/??? fsf x
to advance the tape to x position.
man mt to learn more.

"tar -rf /dev/???? /home/mydirectory/yymmdd/yymmdd.tar "
should be:

 tar -cf /dev/???? /home/mydirectory/yymmdd/yymmdd.tar

I prefer to use relative path, give you more freedom for restoring the files
  eg tar -cf /dev/????  yymmdd.tar
   
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ryeandiAuthor Commented:
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?  
0
yuzhCommented:

"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!

0
ryeandiAuthor Commented:
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?
0
yuzhCommented:
/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  
0
yuzhCommented:
Please read the following page for the tape operations:

http://www.ociw.edu/lco/computer_info/DAT.html
0
ryeandiAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.