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 |
34 |
#$LOG = '/tmp/backup.log'; |
#$LOG = '/tmp/backup.log'; |
35 |
|
|
36 |
# store backups in which directory |
# store backups in which directory |
37 |
#my $BACKUP_DEST = '/backup/isis_backup'; |
my $BACKUP_DEST = '/backup/isis_backup'; |
38 |
my $BACKUP_DEST = '/tmp/backup/'; |
#my $BACKUP_DEST = '/tmp/backup/'; |
39 |
|
|
40 |
# files to ignore in backup |
# files to ignore in backup |
41 |
my @ignore = ('.md5sum', '.backupignore', 'backupignore.txt'); |
my @ignore = ('.md5sum', '.backupignore', 'backupignore.txt'); |
59 |
# taint path: nmblookup should be there! |
# taint path: nmblookup should be there! |
60 |
$ENV{'PATH'} = "/usr/bin:/bin"; |
$ENV{'PATH'} = "/usr/bin:/bin"; |
61 |
|
|
62 |
|
my $use_ping = 1; # deault: use ping to verify that host is up |
63 |
|
|
64 |
|
my $result = GetOptions( |
65 |
|
"ping!" => \$use_ping, "backupdest!" => \$BACKUP_DEST, |
66 |
|
); |
67 |
|
|
68 |
my $mounts = shift @ARGV || |
my $mounts = shift @ARGV || |
69 |
'mountscript'; |
'mountscript'; |
70 |
# die "usage: $0 mountscript"; |
# die "usage: $0 mountscript"; |
72 |
|
|
73 |
my @in_backup; # shares which are backeduped this run |
my @in_backup; # shares which are backeduped this run |
74 |
|
|
75 |
my $p = new Net::Ping->new("tcp", 2); |
my $ping; |
76 |
# ping will try tcp connect to netbios-ssn (139) |
if ($use_ping) { |
77 |
$p->{port_num} = getservbyname("netbios-ssn", "tcp"); |
$ping = new Net::Ping->new("tcp", 2); |
78 |
|
# ping will try tcp connect to netbios-ssn (139) |
79 |
|
$ping->{port_num} = getservbyname("netbios-ssn", "tcp"); |
80 |
|
} |
81 |
|
|
82 |
my $backup_ok = 0; |
my $backup_ok = 0; |
83 |
|
|
139 |
|
|
140 |
if ($ip) { |
if ($ip) { |
141 |
xlog($share,"IP is $ip"); |
xlog($share,"IP is $ip"); |
142 |
if ($p->ping($ip)) { |
if (($use_ping && $ping->ping($ip)) || 1) { |
143 |
if (snap_share($share,$user,$passwd,$workgroup)) { |
if (snap_share($share,$user,$passwd,$workgroup)) { |
144 |
$backup_ok++; |
$backup_ok++; |
145 |
} |
} |
269 |
my %file_atime; |
my %file_atime; |
270 |
my %file_mtime; |
my %file_mtime; |
271 |
#my %file_md5; |
#my %file_md5; |
272 |
|
%file_md5 = (); |
273 |
|
|
274 |
my @smb_files; |
my @smb_files; |
275 |
my %smb_size; |
my %smb_size; |
501 |
# remove files |
# remove files |
502 |
foreach (sort @files2erase) { |
foreach (sort @files2erase) { |
503 |
unlink "$bc/$_" || warn "unlink $_: $!\n"; |
unlink "$bc/$_" || warn "unlink $_: $!\n"; |
504 |
|
delete $file_md5{$_}; |
505 |
} |
} |
506 |
|
|
507 |
# remove not needed dirs (after files) |
# remove not needed dirs (after files) |
514 |
unlink "$bc/$_/.md5sum" if (-e "$bc/$_/.md5sum"); |
unlink "$bc/$_/.md5sum" if (-e "$bc/$_/.md5sum"); |
515 |
} |
} |
516 |
|
|
517 |
|
# erase stale entries in .md5sum |
518 |
|
my @md5_files = keys %file_md5; |
519 |
|
$lc = List::Compare->new(\@md5_files, \@smb_files); |
520 |
|
foreach my $file ($lc->get_Lonly) { |
521 |
|
xlog("NOTICE","removing stale '$file' from .md5sum"); |
522 |
|
delete $file_md5{$file}; |
523 |
|
} |
524 |
|
|
525 |
# create .md5sum |
# create .md5sum |
526 |
my $last_dir = ''; |
my $last_dir = ''; |
527 |
my $md5; |
my $md5; |