[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: backup using hard disk - any ideas



When JonesMB wrote, I replied:

I assume that your 2Gb. is on a different spindle, 'cause if it isn't,
it won't do you a hell of a lot of good in the event of a disk failure.

I've enclosed the perl that I use to backup some essentials that I'd
need to re-build from a Debian CD.  I save only essentials, because my
backup disk holds only 340 Mb. while my system disk is 2 Gb.  This perl
was the result of fooling with various list of directories until I had a
list that saves what I need in ~300 Mb.
> 
> Hello,
> 
> I recently had a hard drive die on me causing me to lose lots of data.  I
> have rebuilt my system (a K6/233 with Debian on 1GB and Win95 on 1GB) and I'm
> looking at various ways of backing up my data so I don't lose it all again.
> I currently have about 2 GB of drive space that I am not using and want to
> devote to backing up my system.  At worst I can just do a cpio or tar but I
> am sure there is a more elegant way to do it.  There might even be a package
> which does this.  Any ideas are appreciated.
> 
> TIA
> jmb
> 
> --
> Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null

-- 
-----------------------------------------
Ralph Winslow		      rjw@nac.net
<Insert sardonic phrase here>
#!/usr/bin/perl -w
# backup - save some volatile and useful directories

$Debug = 1;

# assure that the backup device is available
open(DF,'df -k |') || die "$0: can't pipe from df: $!\n";
while(<DF>) { if(m#\s+/backup\W#) { $On = 1; }; };
close(DF);
if(!$On)
    { $cmd = "mount /dev/hdc1 /backup";
    system($cmd);
    };
open(DF,'df -k |') || die "$0: can't pipe from df: $!\n";
while(<DF>) { if(m#\s+/backup\W#) { $On = 1; }; };
close(DF);
if(!$On) { die "$0: can't mount backup disk\n"; };

foreach $DIR ('root', 'etc', 'home/rjw', 'home/ralphw')
    { $Back = "/backup/$DIR";
    if($Debug) { print "$DIR -> $Back "; };
    $DirSz = &dir_size($Back);
    $cmd = "cd /backup; /bin/rm -rf $DIR";
    system($cmd);
    $DirSz = &dir_size("/$DIR");
    # the dir_size routine does a chdir to the named directory
    $cmd = "find . -print | cpio -pamd /backup/$DIR 2>/dev/null";
    system($cmd);
    $CpySz = &dir_size("/backup/$DIR");
    if($CpySz != $DirSz)
	{ print "The copy of $DIR: $DirSz is $CpySz, instead\n"; };
    if($Debug) { print "$DIR: $DirSz should equal $CpySz\n"; };
    };
exit;

# dir_size - change to the specified directory, find and return the total blocks
#	in it and its recursive sub-directories
sub dir_size {
my ($DIR) = @_;
my $DirSz = 0;

chdir($DIR) || die "$0: can't cd to $DIR: $!\n";
open(DU,'du -s . |') || die "$0: can't pipe from du on $DIR: $!\n";
$DirSz = <DU>; close(DU);
chomp  $DirSz;
$DirSz =~ s/\s+\.+\s*//;
if($Debug) { print "$DIR: $DirSz: "; };
return $DirSz;
}

Reply to: