The way your shell program is written, the first argument to the tar
command ($TAR) is the tape drive ($TAPE); i.e., /dev/IBMtape0
. So, the tape is
the tape archive (that's what tar
means, an acronym of t
chive. So, what you see on the tape is a list of directory and file names that are a copy of the location (directory) and content (file).
The other way to look at that is if you used tar
to create a file named, say, 2012-06-14.tar
(for example) somewhere on your disk drive(s) then compress that into what's called a tarball
) then copy that to the tape as one big (but compressed) tar
archive. You'd do that something like this
tar cvf 2012-06-14.tar $DIR $BACKUP_ROOT_DIR
<wait a while>
<which compresses the archive into 2012-06-14.tar.gz>
cp 2012-06-14.tar.gz /dev/IBMtape0
You can do that in a pipeline (see below) but those are the basic steps to get a date stamped compressed archive on tape (or CD-ROM or DVD or Blu-ray disc media for that matter). The way your shell program is doing it, the archive is not compressed or date stamped.
You have to consider, though, whether you have sufficient room on the tape for more than one back up of the system root (or whatever file tree on the disk drive) directory (some tape systems do, some don't, some will write on more than one cartridge, some won't). It may be simpler to, you know, write the date on the label and be done with it.
A slick way to create the archive file name is
tar -cvf `date +%F`.tar.gz <other arguments>
If you want to add a directory name to that
tar -cvf /tmp/`date +%F`.tar <other arguments>
Those "`...` are "sideways pipes," they can also be done $(date +%F)
(definitely in KornShell, pretty sure in BASH too).
Now, let's combine stuff.
You can compress on-the-fly by adding z
in the tar
tar -czvf /tmp/`date +%F`.tar.gz <other arguments>
(replace the z
You might want to avoid the v
(which shows you the file names) unless you're keeping a log.
So, all in one go
# Create a date stamp name for the archive
# Create a gzip tar archive in /tmp/yyyy-mm-dd.tar.gz
tar czf $FILE_NAME $DIR $BACKUP_ROOT_DIR
# Copy the archive file to tape
cp $FILE_NAME $TAPE
# Remove the archive file
You can do the entire thing in one line but you have to use dd
to do it which means that you have to know the input block size of the tape and some other stuff. Just as easy to use two line to accomplish the job.
Hope this helps some.