--- psinib.pl 2003/10/12 15:58:28 1.11 +++ psinib.pl 2003/10/12 16:13:38 1.12 @@ -33,7 +33,8 @@ #$LOG = '/tmp/backup.log'; # store backups in which directory -my $BACKUP_DEST = '/backup/isis_backup'; +#my $BACKUP_DEST = '/backup/isis_backup'; +my $BACKUP_DEST = '/tmp/backup/'; # files to ignore in backup my @ignore = ('.md5sum', '.backupignore', 'backupignore.txt'); @@ -50,7 +51,7 @@ sleep 1; redo if ++$c < 10; # no response for 10 sec, bail out - print STDERR "can't take lock on $LOG -- another $0 running?\n"; + xlog("ABORT","can't take lock on $LOG -- another $0 running?"); exit 1; } @@ -129,8 +130,9 @@ if ($ip) { xlog($share,"IP is $ip"); if ($p->ping($ip)) { - snap_share($share,$user,$passwd,$workgroup); - $backup_ok++; + if (snap_share($share,$user,$passwd,$workgroup)) { + $backup_ok++; + } } } } @@ -229,7 +231,7 @@ if (-l $bc && $real_bl && $real_bl eq $bc) { print "$share allready backuped...\n"; - return; + return 1; } die "You should really create BACKUP_DEST [$BACKUP_DEST] by hand! " if (!-e $BACKUP_DEST); @@ -318,7 +320,7 @@ } elsif (-d $pf) { push @dirs,$pr; } else { - print STDERR "unknown type: $pf\n"; + print STDERR "not file or directory: $pf\n"; } } else { print STDERR "ignored: $pr\n"; @@ -326,7 +328,8 @@ } } - xlog($share,($#files+1)." files and ".($#dirs+1)." dirs on local disk before backup"); + # local dir always include / + xlog($share,($#files+1)." files and ".($#dirs)." dirs on local disk before backup"); # read smb filesystem @@ -341,10 +344,10 @@ my $pf = norm_dir($d,"smb:$share/"); # path full my $D = $smb->opendir($pf); if (! $D) { - xlog($share,"FATAL: $share: $!"); + xlog($share,"FATAL: $share [$pf]: $!"); # remove failing dir delete $smb_dirs[$di]; - next; + return 0; # failed } $di++; @@ -364,7 +367,7 @@ } elsif ($item->[0] == main::SMBC_DIR) { push @smb_dirs,$pr; } else { - print STDERR "unknown type: $pf\n"; + print STDERR "not file or directory [",$item->[0],"]: $pf\n"; } } else { print STDERR "smb ignored: $pr\n"; @@ -372,7 +375,7 @@ } } - xlog($share,($#smb_files+1)." files and ".($#smb_dirs+1)." dirs on remote share"); + xlog($share,($#smb_files+1)." files and ".($#smb_dirs)." dirs on remote share"); # sync dirs my $lc = List::Compare->new(\@dirs, \@smb_dirs); @@ -404,16 +407,16 @@ foreach my $f (@_) { #print "smb_copy $from/$f -> $to/$f\n"; - if (! open(F,"> $to/$f")) { - print STDERR "can't open new file $to/$f: $!\n"; - next; - } - my $md5 = Digest::MD5->new; my $fd = $smb->open("$from/$f"); if (! $fd) { - print STDERR "can't open smb file $from/$f: $!\n"; + xlog("WARNING","can't open smb file $from/$f: $!"); + next; + } + + if (! open(F,"> $to/$f")) { + xlog("WARNING","can't open new file $to/$f: $!"); next; } @@ -527,8 +530,9 @@ xlog($share,"failed to create latest symlink $bl -> $bc...") if (readlink($bl) ne $bc || ! -l $bl); xlog($share,"backup completed..."); -} + return 1; +} __END__ #-------------------------------------------------------------------------