LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
Search this Thread
Old 06-03-2006, 08:44 AM   #1
MattCarp
LQ Newbie
 
Registered: Jun 2006
Location: Atlanta, GA
Distribution: Ubuntu 6.06
Posts: 4

Rep: Reputation: 0
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
 
Old 06-04-2006, 01:09 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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
 
Old 06-04-2006, 09:16 AM   #3
MattCarp
LQ Newbie
 
Registered: Jun 2006
Location: Atlanta, GA
Distribution: Ubuntu 6.06
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 06-04-2006, 04:11 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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

Last edited by Tinkster; 06-04-2006 at 04:13 PM.
 
Old 06-05-2006, 08:15 AM   #5
MattCarp
LQ Newbie
 
Registered: Jun 2006
Location: Atlanta, GA
Distribution: Ubuntu 6.06
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tar tar cvf - . | (cd /root/; tar xvf -) ewt3y Linux - General 10 02-19-2014 10:55 AM
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 10 02-23-2008 05:40 AM
GNU tar problem :( John Micheal Solaris / OpenSolaris 4 05-25-2005 02:48 PM
Diferance between rpm, tar, tar.gz, scr.tar, etc mobassir Linux - General 12 08-21-2003 06:30 AM
GNU tar ignoring -X? akohlsmith Linux - General 0 07-12-2002 08:57 AM


All times are GMT -5. The time now is 11:48 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration