/[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.12 by dpavlin, Sun Oct 12 16:13:38 2003 UTC revision 1.16 by dpavlin, Sun Oct 26 12:55:56 2003 UTC
# Line 24  use Filesys::SmbClient; Line 24  use Filesys::SmbClient;
24  use Fcntl qw(LOCK_EX LOCK_NB);  use Fcntl qw(LOCK_EX LOCK_NB);
25  use Digest::MD5;  use Digest::MD5;
26  use File::Basename;  use File::Basename;
27    use Getopt::Long;
28    
29  # configuration  # configuration
30  my $LOG_TIME_FMT = '%Y-%m-%d %H:%M:%S'; # strftime format for logfile  my $LOG_TIME_FMT = '%Y-%m-%d %H:%M:%S'; # strftime format for logfile
31  my $DIR_TIME_FMT = '%Y%m%d';            # strftime format for backup dir  my $DIR_TIME_FMT = '%Y%m%d';            # strftime format for backup dir
32    
33    # define timeout for ping
34    my $PING_TIMEOUT = 5;
35    
36  my $LOG = '/var/log/backup.log';        # add path here...  my $LOG = '/var/log/backup.log';        # add path here...
37  #$LOG = '/tmp/backup.log';  #$LOG = '/tmp/backup.log';
38    
39  # store backups in which directory  # store backups in which directory
40  #my $BACKUP_DEST = '/backup/isis_backup';  my $BACKUP_DEST = '/backup/isis_backup';
41  my $BACKUP_DEST = '/tmp/backup/';  #my $BACKUP_DEST = '/tmp/backup/';
42    
43  # files to ignore in backup  # files to ignore in backup
44  my @ignore = ('.md5sum', '.backupignore', 'backupignore.txt');  my @ignore = ('.md5sum', '.backupignore', 'backupignore.txt');
# Line 58  my $c = 0; Line 62  my $c = 0;
62  # taint path: nmblookup should be there!  # taint path: nmblookup should be there!
63  $ENV{'PATH'} = "/usr/bin:/bin";  $ENV{'PATH'} = "/usr/bin:/bin";
64    
65    my $use_ping = 1;       # deault: use ping to verify that host is up
66    
67    my $result = GetOptions(
68            "ping!" => \$use_ping, "backupdest!" => \$BACKUP_DEST,
69    );
70    
71  my $mounts = shift @ARGV ||  my $mounts = shift @ARGV ||
72          'mountscript';          'mountscript';
73  #       die "usage: $0 mountscript";  #       die "usage: $0 mountscript";
# Line 65  my $mounts = shift @ARGV || Line 75  my $mounts = shift @ARGV ||
75    
76  my @in_backup;  # shares which are backeduped this run  my @in_backup;  # shares which are backeduped this run
77    
78  my $p = new Net::Ping->new("tcp", 2);  # init Net::Ping object
79  # ping will try tcp connect to netbios-ssn (139)  my $ping;
80  $p->{port_num} = getservbyname("netbios-ssn", "tcp");  if ($use_ping) {
81            $ping = new Net::Ping->new("syn", 2);
82            # ping will try tcp connect to netbios-ssn (139)
83            $ping->{port_num} = getservbyname("netbios-ssn", "tcp");
84    }
85    
86    # do syn ping to cifs port
87    sub host_up {
88            my $ping = shift || return;
89            my $host_ip = shift || xlog("host_up didn't get IP");
90            my $timeout = shift;
91            return 1 if (! $use_ping);
92    
93            $ping->ping($host_ip,$timeout);
94            my $return = 0;
95    
96            while (my ($host,$rtt,$ip) = $ping->ack) {
97                    xlog("","HOST: $host [$ip] ACKed in $rtt seconds");
98                    $return = 1 if ($ip eq $host_ip);
99            }
100            return $return;
101    }
102    
103  my $backup_ok = 0;  my $backup_ok = 0;
104    
# Line 129  while(<M>) { Line 160  while(<M>) {
160    
161          if ($ip) {          if ($ip) {
162                  xlog($share,"IP is $ip");                  xlog($share,"IP is $ip");
163                  if ($p->ping($ip)) {                  if (host_up($ping, $ip,$PING_TIMEOUT)) {
164                          if (snap_share($share,$user,$passwd,$workgroup)) {                          if (snap_share($share,$user,$passwd,$workgroup)) {
165                                  $backup_ok++;                                  $backup_ok++;
166                          }                          }
# Line 259  sub snap_share { Line 290  sub snap_share {
290          my %file_atime;          my %file_atime;
291          my %file_mtime;          my %file_mtime;
292          #my %file_md5;          #my %file_md5;
293            %file_md5 = ();
294    
295          my @smb_files;          my @smb_files;
296          my %smb_size;          my %smb_size;
# Line 490  sub snap_share { Line 522  sub snap_share {
522          # remove files          # remove files
523          foreach (sort @files2erase) {          foreach (sort @files2erase) {
524                  unlink "$bc/$_" || warn "unlink $_: $!\n";                  unlink "$bc/$_" || warn "unlink $_: $!\n";
525                    delete $file_md5{$_};
526          }          }
527    
528          # remove not needed dirs (after files)          # remove not needed dirs (after files)
# Line 502  sub snap_share { Line 535  sub snap_share {
535                  unlink "$bc/$_/.md5sum" if (-e "$bc/$_/.md5sum");                  unlink "$bc/$_/.md5sum" if (-e "$bc/$_/.md5sum");
536          }          }
537    
538            # erase stale entries in .md5sum
539            my @md5_files = keys %file_md5;
540            $lc = List::Compare->new(\@md5_files, \@smb_files);
541            foreach my $file ($lc->get_Lonly) {
542                    xlog("NOTICE","removing stale '$file' from .md5sum");
543                    delete $file_md5{$file};
544            }
545    
546          # create .md5sum          # create .md5sum
547          my $last_dir = '';          my $last_dir = '';
548          my $md5;          my $md5;
# Line 658  be renamed to I<YYYYMMDD.partial> and sn Line 699  be renamed to I<YYYYMMDD.partial> and sn
699  linking same files (other alternative would be to erase that dir and find  linking same files (other alternative would be to erase that dir and find
700  second-oldest directory, but this seemed like more correct approach).  second-oldest directory, but this seemed like more correct approach).
701    
702    =head2 I can't connect to any share
703    
704    Please verify that nmblookup (which is part of samba package) is in /bin or
705    /usr/bin. Also verify that nmblookup returns IP address for your server
706    using:
707    
708       $ nmblookup tvhouse
709       querying tvhouse on 192.168.34.255
710       192.168.34.30 tvhouse<00>
711    
712    If you don't get any output, your samba might not listen to correct interface
713    (see interfaces in smb.conf).
714    
715  =head1 AUTHOR  =head1 AUTHOR
716    
717  Dobrica Pavlinusic <dpavlin@rot13.org>  Dobrica Pavlinusic <dpavlin@rot13.org>

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

  ViewVC Help
Powered by ViewVC 1.1.26