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 |
|
|
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"; |
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 |
|
|
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 |
} |
} |
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> |