/[psinib]/psinib.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /psinib.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by dpavlin, Tue Jul 15 17:40:32 2003 UTC revision 1.12 by dpavlin, Sun Oct 12 16:13:38 2003 UTC
# Line 33  my $LOG = '/var/log/backup.log';       # add p Line 33  my $LOG = '/var/log/backup.log';       # add p
33  #$LOG = '/tmp/backup.log';  #$LOG = '/tmp/backup.log';
34    
35  # store backups in which directory  # store backups in which directory
36  my $BACKUP_DEST = '/backup/isis_backup';  #my $BACKUP_DEST = '/backup/isis_backup';
37    my $BACKUP_DEST = '/tmp/backup/';
38    
39  # files to ignore in backup  # files to ignore in backup
40  my @ignore = ('.md5sum', '.backupignore', 'backupignore.txt');  my @ignore = ('.md5sum', '.backupignore', 'backupignore.txt');
# Line 50  my $c = 0; Line 51  my $c = 0;
51          sleep 1;          sleep 1;
52          redo if ++$c < 10;          redo if ++$c < 10;
53          # no response for 10 sec, bail out          # no response for 10 sec, bail out
54          print STDERR "can't take lock on $LOG -- another $0 running?\n";          xlog("ABORT","can't take lock on $LOG -- another $0 running?");
55          exit 1;          exit 1;
56  }  }
57    
# Line 81  while(<M>) { Line 82  while(<M>) {
82          next if !/^\s*smbmount\s/;          next if !/^\s*smbmount\s/;
83          my (undef,$share,undef,$opt) = split(/\s+/,$_,4);          my (undef,$share,undef,$opt) = split(/\s+/,$_,4);
84    
85          my ($user,$passwd,$workgroup);          my ($user,$passwd,$workgroup,$ip);
86    
87          foreach (split(/,/,$opt)) {          foreach (split(/,/,$opt)) {
88                  my ($n,$v) = split(/=/,$_,2);                  my ($n,$v) = split(/=/,$_,2);
# Line 97  while(<M>) { Line 98  while(<M>) {
98                          }                          }
99                  } elsif ($n =~ m#workgroup#i) {                  } elsif ($n =~ m#workgroup#i) {
100                          $workgroup = $v;                          $workgroup = $v;
101                    } elsif ($n =~ m#ip#i) {
102                            $ip = $v;
103                  }                  }
104          }          }
105    
# Line 121  while(<M>) { Line 124  while(<M>) {
124    
125          print "working on $share\n";          print "working on $share\n";
126    
127            # try to nmblookup IP
128          my $ip = get_ip($share);          $ip = get_ip($share) if (! $ip);
129    
130          if ($ip) {          if ($ip) {
131                  xlog($share,"IP is $ip");                  xlog($share,"IP is $ip");
132                  if ($p->ping($ip)) {                  if ($p->ping($ip)) {
133                          snap_share($share,$user,$passwd,$workgroup);                          if (snap_share($share,$user,$passwd,$workgroup)) {
134                          $backup_ok++;                                  $backup_ok++;
135                            }
136                  }                  }
137          }          }
138  }  }
# Line 227  sub snap_share { Line 231  sub snap_share {
231    
232          if (-l $bc && $real_bl && $real_bl eq $bc) {          if (-l $bc && $real_bl && $real_bl eq $bc) {
233                  print "$share allready backuped...\n";                  print "$share allready backuped...\n";
234                  return;                  return 1;
235          }          }
236    
237          die "You should really create BACKUP_DEST [$BACKUP_DEST] by hand! " if (!-e $BACKUP_DEST);          die "You should really create BACKUP_DEST [$BACKUP_DEST] by hand! " if (!-e $BACKUP_DEST);
# Line 316  sub snap_share { Line 320  sub snap_share {
320                                  } elsif (-d $pf) {                                  } elsif (-d $pf) {
321                                          push @dirs,$pr;                                          push @dirs,$pr;
322                                  } else {                                  } else {
323                                          print STDERR "unknown type: $pf\n";                                          print STDERR "not file or directory: $pf\n";
324                                  }                                  }
325                          } else {                          } else {
326                                  print STDERR "ignored: $pr\n";                                  print STDERR "ignored: $pr\n";
# Line 324  sub snap_share { Line 328  sub snap_share {
328                  }                  }
329          }          }
330    
331          xlog($share,($#files+1)." files and ".($#dirs+1)." dirs on local disk before backup");          # local dir always include /
332            xlog($share,($#files+1)." files and ".($#dirs)." dirs on local disk before backup");
333    
334          # read smb filesystem          # read smb filesystem
335    
# Line 339  sub snap_share { Line 344  sub snap_share {
344                  my $pf = norm_dir($d,"smb:$share/");    # path full                  my $pf = norm_dir($d,"smb:$share/");    # path full
345                  my $D = $smb->opendir($pf);                  my $D = $smb->opendir($pf);
346                  if (! $D) {                  if (! $D) {
347                          xlog($share,"FATAL: $share: $!");                          xlog($share,"FATAL: $share [$pf]: $!");
348                          # remove failing dir                          # remove failing dir
349                          delete $smb_dirs[$di];                          delete $smb_dirs[$di];
350                          next;                          return 0;                       # failed
351                  }                  }
352                  $di++;                  $di++;
353    
# Line 362  sub snap_share { Line 367  sub snap_share {
367                                  } elsif ($item->[0] == main::SMBC_DIR) {                                  } elsif ($item->[0] == main::SMBC_DIR) {
368                                          push @smb_dirs,$pr;                                          push @smb_dirs,$pr;
369                                  } else {                                  } else {
370                                          print STDERR "unknown type: $pf\n";                                          print STDERR "not file or directory [",$item->[0],"]: $pf\n";
371                                  }                                  }
372                          } else {                          } else {
373                                  print STDERR "smb ignored: $pr\n";                                  print STDERR "smb ignored: $pr\n";
# Line 370  sub snap_share { Line 375  sub snap_share {
375                  }                  }
376          }          }
377    
378          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");
379    
380          # sync dirs          # sync dirs
381          my $lc = List::Compare->new(\@dirs, \@smb_dirs);          my $lc = List::Compare->new(\@dirs, \@smb_dirs);
# Line 402  sub snap_share { Line 407  sub snap_share {
407                                    
408                  foreach my $f (@_) {                  foreach my $f (@_) {
409  #print "smb_copy $from/$f -> $to/$f\n";  #print "smb_copy $from/$f -> $to/$f\n";
                         if (! open(F,"> $to/$f")) {  
                                 print STDERR "can't open new file $to/$f: $!\n";  
                                 next;  
                         }  
   
410                          my $md5 = Digest::MD5->new;                          my $md5 = Digest::MD5->new;
411    
412                          my $fd = $smb->open("$from/$f");                          my $fd = $smb->open("$from/$f");
413                          if (! $fd) {                          if (! $fd) {
414                                  print STDERR "can't open smb file $from/$f: $!\n";                                  xlog("WARNING","can't open smb file $from/$f: $!");
415                                    next;
416                            }
417    
418                            if (! open(F,"> $to/$f")) {
419                                    xlog("WARNING","can't open new file $to/$f: $!");
420                                  next;                                  next;
421                          }                          }
422    
# Line 503  sub snap_share { Line 508  sub snap_share {
508          foreach my $f (sort { $file_md5{$a} cmp $file_md5{$b} } keys %file_md5) {          foreach my $f (sort { $file_md5{$a} cmp $file_md5{$b} } keys %file_md5) {
509                  my $dir = dirname($f);                  my $dir = dirname($f);
510                  my $file = basename($f);                  my $file = basename($f);
511  print "$f -- $dir / $file<--\n";  #print "$f -- $dir / $file<--\n";
512                  if ($dir ne $last_dir) {                  if ($dir ne $last_dir) {
513                          close($md5) if ($md5);                          close($md5) if ($md5);
514                          open($md5, ">> $bc/$dir/.md5sum") || warn "can't create $bc/$dir/.md5sum: $!";                          open($md5, ">> $bc/$dir/.md5sum") || warn "can't create $bc/$dir/.md5sum: $!";
# Line 512  print "$f -- $dir / $file<--\n"; Line 517  print "$f -- $dir / $file<--\n";
517                  }                  }
518                  print $md5 $file_md5{$f},"  $file\n";                  print $md5 $file_md5{$f},"  $file\n";
519          }          }
520          close($md5);          close($md5) if ($md5);
521    
522          # create leatest link          # create leatest link
523  #print "ln -s $bc $real_bl\n";  #print "ln -s $bc $real_bl\n";
# Line 525  print "$f -- $dir / $file<--\n"; Line 530  print "$f -- $dir / $file<--\n";
530          xlog($share,"failed to create latest symlink $bl -> $bc...") if (readlink($bl) ne $bc || ! -l $bl);          xlog($share,"failed to create latest symlink $bl -> $bc...") if (readlink($bl) ne $bc || ! -l $bl);
531    
532          xlog($share,"backup completed...");          xlog($share,"backup completed...");
 }  
533    
534            return 1;
535    }
536  __END__  __END__
537  #-------------------------------------------------------------------------  #-------------------------------------------------------------------------
538    

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.26