Solved

cron file copy to tape

Posted on 2003-10-22
10
338 Views
Last Modified: 2010-04-22
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
0
Comment
Question by:ryeandi
  • 6
  • 4
10 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 9604199
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
 
LVL 38

Expert Comment

by:yuzh
ID: 9604221
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
 
LVL 1

Author Comment

by:ryeandi
ID: 9609195
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
 
LVL 38

Accepted Solution

by:
yuzh earned 250 total points
ID: 9611444
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
 
LVL 1

Author Comment

by:ryeandi
ID: 9615621
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 38

Expert Comment

by:yuzh
ID: 9621690

"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
 
LVL 1

Author Comment

by:ryeandi
ID: 9628557
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
 
LVL 38

Expert Comment

by:yuzh
ID: 9631437
/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
 
LVL 38

Expert Comment

by:yuzh
ID: 9631524
Please read the following page for the tape operations:

http://www.ociw.edu/lco/computer_info/DAT.html
0
 
LVL 1

Author Comment

by:ryeandi
ID: 9772029
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now