1834058 Members
2470 Online
110063 Solutions
New Discussion

Re: newbie tar question!

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

newbie tar question!

Hi all,

can't say that I do many backups at all, so pretty new to tars features!

Currently I have 2 problems:


1>
/home/bill/file1
/home/bill/file2
/home/bill/file3
/home/bill/file4


tar -cvf /bill.tar /home/bill/file1 /home/bill/file2 /home/bill/file3 /home/bill/file4

Great! created a tar file!

vi file1, save and make realise after doing this:

tar -uvf /bill.tar /home/bill/file1

that I made a stupid error.
(and forgot the contents of the original)

now:
tar -tvf /bill.tar
/home/bill/file1 18th June
/home/bill/file2 18th June
/home/bill/file3 18th June
/home/bill/file4 18th June
/home/bill/file1 19th June

mmm, maybe I can recover file1 from the 18th June.. but
not via tar -xvf /bill.tar

How do I do this.

2>

secondly, before I archive this, how can I tar -uvf to really replace the file1, ie, If I don't want the two versions..


Thanks,
Bill
It works for me (tm)
16 REPLIES 16
Michael Tully
Honored Contributor

Re: newbie tar question!

Hey Skip!,

A sys admin of your experience... shame...

You wanted to recover, my suggestion is to
move the original /home/bill to /home/bill1
or something else.
The reason I say this is that when using
tar never, ever use the full pathname,
use ./dir/files

2> Do the same thing again after moving
/home/bill to /home/bill2

Michael
Anyone for a Mutiny ?
Volker Borowski
Honored Contributor

Re: newbie tar question!

Hi Bill,

from "man tar"
Note that if several files with the same name are on the archive, the last one overwrites all earlier ones.

If you want to do some version management for diffrent versions of scripts, configfiles or so, you should take a look at "sccs". I guess without a timestamp based naming convention for tar-archives, tar would not be the right tool. In addition, one should not use absolute pathnames in tar, because you might have trouble to relocate to a diffrent location.

Hope this helps
Volker
Trond Haugen
Honored Contributor

Re: newbie tar question!

Generally if you want to "remove" the leading dir's from a tar you can use pax:
cd where-you-want-the-files
pax -r -s ',//*home/bill//*,,' -f /dev/rmt/0m

For getting the first file1 you could probably start the extraction and interrumt it after having read the first file1, or you can use the '-i' option to pax.

You can't replace a file on a tar, only add (to the end).

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Bill McNAMARA_1
Honored Contributor

Re: newbie tar question!

> start the extraction and
> interrupt it after having
> read the first file1,
It goes a little too fast to do this ;)

> or you can use the '-i' option to pax.

This is good!
But I'd prefer a tar command!

Nobody yet has really answered my question (I don't think you read it fully either!)

For a start, the files do need to be absolute to root because it's a software installation (and my example here is minimal - there are really more than 800 files in the tar, but the problem is the same.)

The tar extraction is handled via a non interuptable install script, and in either case is too quick to interupt.

The questions simply are:

how do I extract both file1's individually via tar.
and,
after the tar is created, how do I delete/upgrade the tar so that only one file1 exists.

I don't think it's possible myself given the origins of tar..

Later,
Bill
It works for me (tm)
Vincent Farrugia
Honored Contributor

Re: newbie tar question!

Hello,

I don't think restoring the old file can be done. The second "file1" will overwrite the first "file1".

I don't think you can remove the first one from the archive either.

Vince
Tape Drives RULE!!!
Trond Haugen
Honored Contributor
Solution

Re: newbie tar question!

1> No, not with tar.
2> No, not with tar.
tar can only ADD files to the (end of the) archive.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Ian Dennison_1
Honored Contributor

Re: newbie tar question!

Bill,

Remember that annoying confirmation message that comes up when trying to overwrite or delete a file as a non-root user, that is owned by someone else?

Try extracting the files once as root, then again as a non-root user. This should (hopefully) force tar to prompt for 'overwrite y/n', so you can selectively restore the files, and perhaps Ctrl-C to halt at the next prompted file?

Also, does the 'tar -uvf' option add to the end, or update the existing file?

Share and Enjoy! Ian
Building a dumber user
harry d brown jr
Honored Contributor

Re: newbie tar question!

Bill,

pax is the only way, UNLESS you get and install GNU's tar.

http://www.sunsite.ualberta.ca/Documentation/Gnu/tar-1.13/html_mono/tar.html

Here's a PAX example:

# tar -tvf zfile.tar
rw-r----- 0/3 105707 Jun 20 07:22 2002 /tmp/zfile1.txt
rw-r----- 0/3 105707 Jun 20 07:22 2002 /tmp/zfile2.txt
rw-r----- 0/3 105707 Jun 20 07:22 2002 /tmp/zfile3.txt
rw-r----- 0/3 105707 Jun 20 07:22 2002 /tmp/zfile4.txt
rw-r----- 0/3 1315 Jun 20 07:23 2002 /tmp/zfile1.txt
# ll zfile*
-rw-rw-rw- 1 root sys 430080 Jun 20 07:23 zfile.tar
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile1.txt
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile2.txt
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile3.txt
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile4.txt
# pax -r -x ustar -y -f zfile.tar
extract /tmp/zfile1.txt? n
extract /tmp/zfile2.txt? n
extract /tmp/zfile3.txt? n
extract /tmp/zfile4.txt? n
extract /tmp/zfile1.txt? y
# ll zfile*
-rw-rw-rw- 1 root sys 430080 Jun 20 07:23 zfile.tar
-rw-r----- 1 root sys 1315 Jun 20 07:23 zfile1.txt
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile2.txt
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile3.txt
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile4.txt
#


live free or die
harry
Live Free or Die
Tim D Fulford
Honored Contributor

Re: newbie tar question!

1 - dont tar things up to / !!!! (This is not so much for your benefit as someone else reading this thread).
2 - Why update your tar file and then change your mind and go back to the old version! It is handy of tar to allow you to do this, but the feature does not extend as far as you would like.... It just so happens that 18 June files can be extracted as Vince has said (effectively utilising a loophole) and if you want the whole 19 June just do full extract.

That said try

18 June
dd if=/bill.tar bs= count= | tar xvf - /.../file1

19 June
tar xvf /bill.tar /..../file1

Regards

Tim
-
Volker Borowski
Honored Contributor

Re: newbie tar question!

In this case not "tar" but "ar" might do what you want ?

"ar" has update and positioning options.

Volker
H.Merijn Brand (procura
Honored Contributor

Re: newbie tar question!

Something like this? [ It might be unsafe! ]

l1:/tmp 105 > tar cvf xx.tar xx.c xx.o
a xx.c 1 blocks
a xx.o 2 blocks
l1:/tmp 106 > tar tvf xx.tar
rw-rw-rw- 203/200 9 May 27 13:23 2002 xx.c
rw-rw-rw- 203/200 732 May 27 13:23 2002 xx.o
l1:/tmp 107 > touch xx.c
l1:/tmp 108 > tar uvf xx.tar xx.c
a xx.c 1 blocks
l1:/tmp 109 > tar tvf xx.tar
rw-rw-rw- 203/200 9 May 27 13:23 2002 xx.c
rw-rw-rw- 203/200 732 May 27 13:23 2002 xx.o
rw-rw-rw- 203/200 9 Jun 20 13:02 2002 xx.c
l1:/tmp 110 >


l1:/tmp/test 144 > xx.pl ../xx.tar
Opening archive ../xx.tar ...
x xx.c ...
x xx.o ...
x xx.c ...
WHOA! xx.c appeared in this archive before
New file extracted as xx.c.1
l1:/tmp/test 145 > ll
total 15
791 drwxrwxrwx 2 merijn softwr 96 Jun 20 13:40 .
2 drwxrwxrwx 19 root root 11264 Jun 20 13:40 ..
837 -rw-rw-rw- 1 merijn softwr 9 May 27 13:23 xx.c
830 -rw-rw-rw- 1 merijn softwr 9 Jun 20 13:02 xx.c.1
839 -rw-rw-rw- 1 merijn softwr 732 May 27 13:23 xx.o
702 -rwxr-xr-x 1 merijn softwr 815 Jun 20 13:40 xx.pl
l1:/tmp/test 146 >

l1:/tmp/test 146 > cat xx.pl
#!/pro/bin/perl -w

use strict;
use Archive::Tar;
use File::Copy;

my %done;
print STDERR "Opening archive $ARGV[0] ...\n";
my $tar = Archive::Tar->new (shift);
for ($tar->list_files ([qw(name uid gid mtime mode)])) {
my $name = $_->{name};
print STDERR "x $name ... ";
my $new = $name;
if ($done{$name}++) {
my $idx = 1;
$idx++ while -f "$new.$idx";
$new .= ".$idx";
print STDERR "\nWHOA! $name appeared in this archive before\n",
"New file extracted as $new";
move ($name, "$new.$$");
}
-f $new and print STDERR " already exists";
$tar->extract ($name);
utime $_->{mtime}, $_->{mtime}, $name;
chmod $_->{mode}, $name;
chown $_->{uid}, $_->{gid}, $name;

print STDERR "\n";
$name eq $new and next;
move ($name, $new);
move ("$new.$$", $name);
}
l1:/tmp/test 147 >
Enjoy, Have FUN! H.Merijn
harry d brown jr
Honored Contributor

Re: newbie tar question!

Bill,

Sorry I screwed up the order you wanted, using pax, it would be like this:

# tar -tvf zfile.tar
rw-r----- 0/3 105707 Jun 20 07:22 2002 /tmp/zfile1.txt
rw-r----- 0/3 105707 Jun 20 07:22 2002 /tmp/zfile2.txt
rw-r----- 0/3 105707 Jun 20 07:22 2002 /tmp/zfile3.txt
rw-r----- 0/3 105707 Jun 20 07:22 2002 /tmp/zfile4.txt
rw-r----- 0/3 1315 Jun 20 07:23 2002 /tmp/zfile1.txt
# pax -r -x ustar -y -f zfile.tar
extract /tmp/zfile1.txt? y
extract /tmp/zfile2.txt? n
extract /tmp/zfile3.txt? n
extract /tmp/zfile4.txt? n
extract /tmp/zfile1.txt? n
# ll zfile*
-rw-rw-rw- 1 root sys 430080 Jun 20 07:23 zfile.tar
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile1.txt
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile2.txt
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile3.txt
-rw-r----- 1 root sys 105707 Jun 20 07:22 zfile4.txt
#


live free or die
harry
Live Free or Die
Bill McNAMARA_1
Honored Contributor

Re: newbie tar question!

Thanks all,

that's cleared that one up!

Later,
Bill
It works for me (tm)
Frank Slootweg
Honored Contributor

Re: newbie tar question!

> The questions simply are:
>
> how do I extract both file1's individually via tar.

Bill, I am somewhat disappointed in you! :-)

First Trond gives a perfectly good solution ("pax -i"). But no, not only are you 'stubborn' enough to not use pax (which is a superset of tar and cpio and an XPG/POSIX standard command to boot), but you miss the 'obvious' clue, "-i"! :-). tar(1) also has a "-i"-like option, only is is called "w":

> Cause tar to print the action being taken, followed by the
> name of the file, then wait for the user's confirmation. If
> the user answers y, the action is performed. Any other
> input means "no".

> and,
> after the tar is created, how do I
> delete/upgrade the tar so that only one file1 exists.

As far as I know, that is not possible.


Brian Kinney
Frequent Advisor

Re: newbie tar question!

STOP! This is NOT a big deal!

tar wxvf /bill.tar /home/bill/file1

This is INTERACTIVE MODE - confirm before each action, just like ftp's "mget" function.

You can pull any file you please from your archive.

Part 2> It would be simplest to extract your old tar file, update the files in question, and create a new tar file from it.

Brian
"Any sufficiently advanced technology can be indistinguishable from magic" Arthur C. Clarke. My corollary - "Any advanced technology can be crushed with a sufficently large enough rock."
Bill McNAMARA_1
Honored Contributor

Re: newbie tar question!

It's a big enough deal to me..
my archives that I'm archiving in a central repository are getting massive because of multiple same file inclusions.
I don't want to have to recreate my entire tar every time I make a simple modification. This literaly takes hours to complete.

Later,
Bill
It works for me (tm)