]> Frank Brehm's Git Trees - my-stuff/postfix.git/commitdiff
Backup eingearbeitet
authorFrank Brehm <frank@brehm-online.com>
Mon, 10 Nov 2008 13:37:07 +0000 (13:37 +0000)
committerFrank Brehm <frank@brehm-online.com>
Mon, 10 Nov 2008 13:37:07 +0000 (13:37 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/postfix@28 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

get-lookup-tables.conf
get-lookup-tables.pl

index 0398c2aa0bb9ced407854f82e425f877374920b3..f03099ae4247b4cf7f1cdfe6ec9f6652615582d3 100644 (file)
@@ -12,6 +12,7 @@
 
 workdir                        /etc/postfix/work
 lookup_dir             /etc/postfix/tables
+backup_dir             /etc/postfix/.old
 pid_file               /var/run/get-lookup-tables.pid
 
 #<binary>
index 76fc200820acf85d9c8b3687e14e8097c702ef52..fe0e172a3d5a25df973c6361ca95ef09b8a1bae4 100755 (executable)
@@ -41,6 +41,7 @@ my $binary = {
 };
 
 my $workdir = catfile( '', 'etc', 'postfix', 'work' );
+my $backup_dir = catfile( '', 'etc', 'postfix', '.old' );
 my $lookup_dir = $postfix_dir;
 
 my $default_database_type = 'hash';
@@ -123,6 +124,7 @@ sub perform_lookup {
 
     my $new_file = catfile( $workdir, $lookup );
     my $cur_file = catfile( $lookup_dir, $lookup );
+    my $backup_file = catfile( $backup_dir, $lookup );
     debug( 1, "Schreibe Ergebnisse in Datei '" . $new_file . "' ..." );
 
     unless ( open FILE, ">", $new_file ) {
@@ -149,6 +151,8 @@ sub perform_lookup {
 
     close FILE;
 
+    $backup_file .= "." . curtime(1);
+
     my $changed = 0;
 
     $changed = 1 unless -f $cur_file;
@@ -159,6 +163,8 @@ sub perform_lookup {
         debug( 0, "Aktualisiere Lookup-Tabelle '" . $lookup . "'." );
         debug( 1, "Kopiere '" . $new_file . "' nach '" . $cur_file . "' ..." );
         copy $new_file, $cur_file;
+        debug( 1, "Kopiere '" . $new_file . "' als Backup nach '" . $backup_file . "' ..." );
+        copy $new_file, $backup_file;
 
         if ( $type eq 'btree' or $type eq 'dbm' or $type eq 'hash' ) {
             my $cmd = $map_type eq 'aliases' ? $binary->{'postalias'} : $binary->{'postmap'};
@@ -411,16 +417,22 @@ sub parse_line {
 
 #--------------------------------------------------------------------------------------
 
-=head2 curtime( )
+=head2 curtime( [ $for_filename ] )
 
 =cut
 
 sub curtime {
 
+    my $for_filename = shift;
     my $out = '';
 
+    my $template = $for_filename ? '%4d-%02d-%02d_%02d-%02d-%02d%s' : '%4d-%02d-%02d %02d:%02d:%02d%s';
+
+    my $tz = $ENV{'TZ'} ? ' ' . $ENV{'TZ'} : '';
+    $tz = '' if $for_filename;
+
     my @LT = localtime();
-    $out = sprintf( '%4d-%02d-%02d %02d:%02d:%02d%s', $LT[5] + 1900, $LT[4] + 1, $LT[3], $LT[2] ,$LT[1], $LT[0], ( $ENV{'TZ'} ? ' ' . $ENV{'TZ'} : '' ) );
+    $out = sprintf( $template, $LT[5] + 1900, $LT[4] + 1, $LT[3], $LT[2] ,$LT[1], $LT[0], $tz );
     return $out;
 
 }
@@ -511,6 +523,10 @@ sub check_binaries {
     debug( 3, "Checke Verzeichnis für Lookup-Tabellen '" . $lookup_dir . "' ..." );
     fatal( "Verzeichnis fuer Lookup-Tabellen '" . $lookup_dir . "' existiert nicht." ) unless -d $lookup_dir;
 
+    $backup_dir = $config->{'backup_dir'} if $config->{'backup_dir'};
+    debug( 3, "Checke Backup-Verzeichnis '" . $backup_dir . "' ..." );
+    fatal( "Backup-Verzeichnis '" . $backup_dir . "' existiert nicht." ) unless -d $backup_dir;
+
     for my $bin ( keys %$binary ) {
         if ( $config->{'binary'}{$bin} ) {
             $binary->{$bin} = $config->{'binary'}{$bin};