--- psinib.pl 2003/01/04 11:42:56 1.1 +++ psinib.pl 2003/01/04 13:29:12 1.3 @@ -21,6 +21,7 @@ use List::Compare; use Filesys::SmbClient; #use Taint; +use Fcntl qw(LOCK_EX LOCK_NB); # configuration my $LOG_TIME_FMT = '%Y-%m-%d %H:%M:%S'; # strftime format for logfile @@ -39,6 +40,18 @@ open(L, "> $LOG") || die "can't open log $LOG: $!"; select((select(L), $|=1)[0]); # flush output +# make a lock on logfile + +my $c = 0; +{ + flock L, LOCK_EX | LOCK_NB and last; + 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"; + exit 1; +} + # taint path: nmblookup should be there! $ENV{'PATH'} = "/usr/bin:/bin"; @@ -426,5 +439,92 @@ xlog($share,"backup completed..."); } +__END__ #------------------------------------------------------------------------- + +=head1 NAME + +psinib - Perl Snapshot Is Not Incremental Backup + +=head1 SYNOPSIS + +./psinib.pl + +=head1 DESCRIPTION + +This script in current version support just backup of Samba (or Micro$oft +Winblowz) shares to central disk space. Central disk space is organized in +multiple directories named after: + +=over 4 + +=item * +server which is sharing files to be backed up + +=item * +name of share on server + +=item * +dated directory named like standard ISO date format (YYYYMMDD). + +=back + +In each dated directory you will find I of all files on +exported share on that particular date. + +You can also use symlink I which will lead you to +last completed backup. After that you can use some other backup +software to transfer I to tape, CD-ROM or some other media. + +=head2 Design considerations + +Since taking of share snapshot every day requires a lot of disk space and +network bandwidth, B uses several techniques to keep disk usage and +network traffic at acceptable level: + +=over 3 + +=item - usage of hard-links to provide same files in each snapshot (as opposed +to have multiple copies of same file) + +=item - usage of file size, atime and mtime to find changes of files without +transferring whole file over network (just share browsing is transfered +over network) + +=item - usage of C<.md5sum> files (compatible with command-line utility +C to keep file between snapshots hard-linked + +=back + +=head1 CONFIGURATION + +This section is not yet written. + +=head1 BUGS and LIMITATIONS + +There is not real reason why you can't take snapshot more often than +one a day. Actually, if you are using B to backup Windows workstations +they tend to come-and-go, so running B several times a day +increases your chance of having up-to-date backup (B will not +make multiple backups for same day if such backup already exists). + +However, changing that to produce backups which are, for example, hourly +is a simple change of C<$DIR_TIME_FMT> which is currently set to +C<'%Y%m%d'> (see I documentation for explanation of that +format). If you change that to C<'%Y%m%d-%H> you can have hourly snapshots +(if your network is fast enough, that is...). Also, some of messages in +program will sound strange, but other than that it should work. +I. + +=head1 AUTHOR + +Dobrica Pavlinusic + +L + +=head1 LICENSE + +This product is licensed under GNU Public License (GPL) v2 or later. + +=cut