1 #!/usr/bin/perl
 2 # Written by Michael Howe, in a desparate attempt to get tar to backup a 63GB
 3 # partition onto a filesystem that has a maximum size of 4GB.
 4 # Usage:
 5 #   Change $filename and $dir to the base filename (ie without .tar) and
 6 #   directory of the tar files.
 7 #   Then, use tar:
 8 #   tar -cvvM -L4194200 -F /path/to/this/script.pl -f /path/to/tar/file.tar /dir/to/tar
 9 #   tar will create 'file.tar', then when it gets to just under 4G, will call
10 #   this script, which will move file.tar to file.00.tar, and start again on
11 #   file.tar.
12 #   Upon completion of the tar command, move file.tar to be the last in the
13 #   series (ie file.01.tar (if the only other file is file.00.tar)).
14 #
15 # IMPORTANT:
16 #   This may well eat your data, and could also fry your hardware, or (worst
17 #   case) lead to an alien invasion.  I claim no responsibility - use at your
18 #   own risk (and remember to backup).
19 use strict;
20 use warnings;
21 use File::Copy;
22 
23 my $filename = "src";
24 my $dir = "/tmp/tartest";
25 
26 my $latest = `ls -1 $dir/$filename.*.tar 2>/dev/null| sort | tail -1`;
27 
28 my $newname;
29 print "Latest: $latest\n";
30 if ( $latest ) {
31 	my ( $number ) = $latest =~ m{.*\.(\d+)\.tar};
32 	$number++;
33 	print "Number: $number\n";
34 	$newname = sprintf( "%s/%s.%02d.tar", $dir, $filename, $number );
35 	( -f $newname ) && die "File $newname exists - script screwed!";
36 } else {
37 	$newname = "$dir/$filename.00.tar";
38 }
39 
40 
41 move( "$dir/$filename.tar", $newname );
42 ( -f $newname ) and exit 0;


syntax highlighted by Code2HTML, v. 0.9.1