summaryrefslogtreecommitdiff
path: root/Echolot
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2002-09-21 03:24:41 +0000
committerPeter Palfrader <peter@palfrader.org>2002-09-21 03:24:41 +0000
commitb2e64a659da60e52e4393badf6565186bca12d01 (patch)
treeb6b25fbc3a9656481ee26949ced5b7a45f5c068a /Echolot
parent5082f3c7fd852bae98e1c0e252ad19a9bfbb6d0c (diff)
Die immeditatly if there is no Version information in metadataecholot-2.0.2
Make regular backups of metadata and rotate them properly
Diffstat (limited to 'Echolot')
-rw-r--r--Echolot/Config.pm6
-rw-r--r--Echolot/Storage/File.pm41
2 files changed, 44 insertions, 3 deletions
diff --git a/Echolot/Config.pm b/Echolot/Config.pm
index a88367a..2e386b0 100644
--- a/Echolot/Config.pm
+++ b/Echolot/Config.pm
@@ -1,7 +1,7 @@
package Echolot::Config;
# (c) 2002 Peter Palfrader <peter@palfrader.org>
-# $Id: Config.pm,v 1.40 2002/09/12 15:41:49 weasel Exp $
+# $Id: Config.pm,v 1.41 2002/09/21 03:24:41 weasel Exp $
#
=pod
@@ -91,6 +91,9 @@ sub init($) {
getkeyconf_every_nth_time => 24*60/5, # send out the same request to the same remailer once a day
check_resurrection => 7*24*60*60, # weekly
+ metadata_backup => 8*60*60, # make backups of metadata and rotate them every 8 hours
+ metadata_backup_count => 32, # keep 32 rotations of metadata
+
pinger_interval => 5*60, # send out pings every 5 minutes
ping_every_nth_time => 48, # send out pings to the same remailer every 48 calls, i.e. every 4 hours
@@ -120,6 +123,7 @@ sub init($) {
broken1 => 'broken1.txt',
broken2 => 'broken2.txt',
sameop => 'sameop.txt',
+ gzip => 'gzip',
commands_file => 'commands.txt',
pidfile => 'pingd.pid',
diff --git a/Echolot/Storage/File.pm b/Echolot/Storage/File.pm
index c71e4e8..b2b23d4 100644
--- a/Echolot/Storage/File.pm
+++ b/Echolot/Storage/File.pm
@@ -1,7 +1,7 @@
package Echolot::Storage::File;
# (c) 2002 Peter Palfrader <peter@palfrader.org>
-# $Id: File.pm,v 1.40 2002/09/05 15:41:38 weasel Exp $
+# $Id: File.pm,v 1.41 2002/09/21 03:24:41 weasel Exp $
#
=pod
@@ -129,6 +129,7 @@ sub metadata_open($) {
flock($self->{'METADATA_FH'}, LOCK_EX) or
cluck("Cannot get exclusive lock on $filename: $!"),
return 0;
+ return 1;
};
sub metadata_close($) {
@@ -140,6 +141,7 @@ sub metadata_close($) {
close($self->{'METADATA_FH'}) or
cluck("Error when closing metadata file: $!"),
return 0;
+ return 1;
};
@@ -172,7 +174,7 @@ sub metadata_read($) {
return 0;
defined($self->{'METADATA'}->{'version'}) or
- cluck("Stored data lacks version header"),
+ confess("Stored data lacks version header"),
return 0;
($self->{'METADATA'}->{'version'} == ($METADATA_VERSION)) or
cluck("Metadata version mismatch ($self->{'METADATA'}->{'version'} vs. $METADATA_VERSION)"),
@@ -209,6 +211,41 @@ sub metadata_write($) {
return 1;
};
+sub metadata_backup($) {
+ my ($self) = @_;
+
+ my $filename = $self->{'datadir'} .'/'. $CONSTANTS->{'metadatafile'};
+ for (my $i=Echolot::Config::get()->{'metadata_backup_count'} - 1; $i>=0; $i--) {
+ rename ($filename.'.'.($i) , $filename.'.'.($i+1));
+ rename ($filename.'.'.($i).'.gz', $filename.'.'.($i+1).'.gz');
+ };
+ $filename .= '.1';
+
+
+ my $data = Data::Dumper->Dump( [ $self->{'METADATA'} ], [ 'METADATA' ] );
+ my $fh = new IO::Handle;
+ open ($fh, '>'.$filename) or
+ cluck("Cannot open $filename for writing: $!"),
+ return 0;
+ print($fh "# vim:set syntax=perl:\n") or
+ cluck("Error when writing to metadata file: $!"),
+ return 0;
+ print($fh $data) or
+ cluck("Error when writing to metadata file: $!"),
+ return 0;
+ $fh->flush();
+ close($fh) or
+ cluck("Error when closing metadata file: $!"),
+ return 0;
+
+ if (Echolot::Config::get()->{'gzip'}) {
+ system(Echolot::Config::get()->{'gzip'}, $filename) and
+ cluck("Gziping $filename faild."),
+ return 0;
+ };
+
+ return 1;
+};