LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   need some help with muli-volume tar (ubuntu, bash, gnu tar) (https://www.linuxquestions.org/questions/linux-general-1/need-some-help-with-muli-volume-tar-ubuntu-bash-gnu-tar-451187/)

MattCarp 06-03-2006 08:44 AM

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 run the following command as root:

tar -c -v -p -M -L 2097152 -f '/media/usbdisk/fullbackup' -X '/media/usbdisk/backup.exclude' --info-script='/media/usbdisk/backup.nextvol' /

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?

Thanks, Matt

Tinkster 06-04-2006 01:09 AM

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.


Cheers,
Tink

MattCarp 06-04-2006 09:16 AM

Thanks for the help.

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).

so, here's the command I went with:

Code:

tar -c -v -p -j -X '/media/usbdisk/backup/backup.exclude' / | split -d -b 1999m - /media/usbdisk/backup/fullbackup.tar.bz2.
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.

Tinkster 06-04-2006 04:11 PM

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 ;}


Cheers,
Tink

MattCarp 06-05-2006 08:15 AM

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.


All times are GMT -5. The time now is 12:45 AM.