[NTLUG:Discuss] cop files with dynamic prefix
David Stanaway
david at stanaway.net
Sun Dec 17 00:24:01 CST 2006
This is a little perl script I started working on a while back which
pretty much does what you want.
#! /usr/bin/perl -w
use File::Path;
my $BUDIR='/mnt/backup/test';
my $SAVESETS={
etc => ['full',['/etc']]
};
foreach my $name (keys %{$SAVESETS}) {
my $level = ${$SAVESETS->{$name}}[0];
my $paths = ${$SAVESETS->{$name}}[1];
my $fh = prepSaveSetIDX($name,$level);
my $plist = q{"}.join(q{" "},@{$paths}).q{"};
my $tarcmd = qq{tar -cpsvf "$fh->{SSDF}" $plist\n};
print {$fh->{SSIFH}} $tarcmd;
open TARPIPE, "$tarcmd|";
while(<TARPIPE>) {
print {$fh->{SSIFH}} $_;
}
close TARPIPE;
close $fh->{SSIFH};
}
sub prepSaveSetIDX {
my ($name,$level) = @_;
my $ts = time();
my $idxfile = "$BUDIR/index/$name/$ts";
my $datadir = "$BUDIR/data/$name/$ts";
my $datafile = "$datadir/$name-$level.tgz";
mkpath "$BUDIR/index/$name";
mkpath $datadir;
print "name[$name] level[$level] -> $idxfile\n";
open my $ssifh, ">$idxfile";
print $ssifh "$level:$name\n";
return { SSIFH=>$ssifh, SSDF=>$datafile };
}
I had ambitions of making it do full, differential and incremental
backups and retention management. I might get around to it.
david at sprocket:/mnt/backup$ ls -lAR test
test:
total 0
drwxr-xr-x 4 30816 30816 27 2006-09-17 10:07 data
drwxr-xr-x 4 30816 30816 27 2006-09-17 10:07 index
test/data:
total 0
drwxr-xr-x 10 30816 30816 142 2006-12-17 00:12 etc
test/data/etc:
total 0
drwxr-xr-x 2 30816 30816 25 2006-12-17 00:11 1166335858
drwxr-xr-x 2 30816 30816 25 2006-12-17 00:12 1166335928
test/data/etc/1166335858:
total 3980
-rw-r--r-- 1 30816 30816 4075520 2006-12-17 00:11 etc-full.tgz
test/data/etc/1166335928:
total 4132
-rw-r--r-- 1 30816 30816 4229120 2006-12-17 00:13 etc-full.tgz
test/index:
total 0
drwxr-xr-x 2 30816 30816 142 2006-12-17 00:12 etc
test/index/etc:
total 332
-rw-r--r-- 1 30816 30816 42374 2006-12-17 00:11 1166335858
-rw-r--r-- 1 30816 30816 42835 2006-12-17 00:13 1166335928
m m wrote:
> All:
>
> Can anyone help me with a script?
>
> 1. copy all files and sub directories in myfolder to backup directory
> 2. create a directory under backup and automatically add date as prefix
> 3. copy all files and sub directories in myfolder to newcreated directory
>
> for example
>
> the original folder/files
> somepath/myfolder/*
>
> after copy on the day of 12/14
> the folder will have
> backup/myfolder12142006/*
>
> and
>
> after copy on the day of 12/14
> the folder will have
> backup/myfolder12142006/*
> backup/myfolder12152006/*
> ...
>
> Does the shell can do it or need other 'language' tool (such as perl...) to
> achieve this task?
> Any code example would be appreciated!
>
> thanks.
>
> _________________________________________________________________
> MSN Shopping has everything on your holiday list. Get expert picks by style,
> age, and price. Try it!
> http://shopping.msn.com/content/shp/?ctId=8000,ptnrid=176,ptnrdata=200601&tcode=wlmtagline
>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list