need some help with muli-volume tar (ubuntu, bash, gnu tar)
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
need some help with muli-volume tar (ubuntu, bash, gnu tar)
I'm working on creating a routine backup scheme and am having a problem with creating a multi-volume backup with GNU tar 1.15 included with the Ubuntu 6.06 Linux distro.
First I'd like to start with just using tar to create a full backup.
My destination device is either an external USB connected hard disk, or a samba file share. The destination file system is FAT (2G limit!). My goal is to do a full backup of the file system in 2G tarballs, with a sequential number as part of the filename.
I'm having a problem getting the --info-script. It successfully launches the script, but I have no idea how to communicate between tar and the script.
The documentation on gnu.org shows a sh script example, but I'm using the bash shell.
Unfortunately, the example doesn't work in bash - the "file descriptor 3 (>&3)" seems to be invalid, and I don't see the tar environment variables. I've created a dummy script that lists out the environment variables (a "set" command) and there do not appear any TAR_* environment variables.
I'm not yet a bash/tar/*nix guru, so that could be the problem. Is anyone out there smart enough to solve the problem?
In the original script that you're using as a template, is the
descriptor being defined somewhere above the line where it's
being used in the way you're trying to use it? Basically bash
is a super-set of bourne, and pretty downwards compatible.
Interesting. The descriptors are not declared in the info-script called from tar. I'm not sure what you mean, though.
Here's the script:
Code:
#! /bin/sh
echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
# name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
case $TAR_SUBCOMMAND in
-c) ;;
-d|-x|-t) test -r ${name:-$TAR_ARCHIVE}-$TAR_VOLUME || exit 1
;;
*) exit 1
esac
echo ${name:-$TAR_ARCHIVE}-$TAR_VOLUME >&3
So, when it runs, TAR_VOLUME and TAR_ARCHIVE are blank. According to Gnu tar documentation,those vairables are set when the script is called.
I actually took a different approach. I gave up on trying to get tar multi-volume to work and just piped tar to the split command. I think might be a better approach because it also allows me to use the bzip2 to compress the backup (whereas tar multi-volumes do not).
This created a nice set of files, fullbackup.tar.bz2.00 and fullbackup.tar.bz2.01
However, I'm interested in the tar multi-volume info-script puzzle if anyone knows the answer. This whole defining the descriptor thing sound like a lesson for me.
Well, I've never used more file-descriptors than the 3 bash provides
by default, but my understanding is that use another one you'd need
to tie it to a file of sorts, e.g. exec n>some-file
That's what happens in configure scripts all the time. I'd guess that
the shell (without such methods) wouldn't know what to do with the
data that you then try to redirect to 3.
In addition to that: multi-volume tar was originally meant
for tapes and the likes, where you actually swap the device
over when the first one is filled up, hence there was no need
for any scripting at the end. But I like the theory, and
will examine it ;}
A response from the help-tar gnu mailing list tells me that the lack of $TAR_* variables is likely due to the fact that I'm using an older version of tar (1.15.1 installed with ubuntu 6.06) than 1.15.90, which is what is documented online.
So, I think that solves the mystery.
If I'm to use the multi-volume support and info-script, my script would have to rename the archive file just created, instead of specifying the name of the next archive file.
Code:
#/bin/sh
#
# tar writes to a file, fullbackup
a=0
while [ -e ./fullbackup*.$a ]; do
a=`expr $a \+ 1`;
done
echo renaming to fullbackup.$a
mv fullbackup fullbackup.$a
Of course, I'd want to call tar from a script that also executes this info-script to rename the final file tar creates, keeping the set in sequential order.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.