From 6f2ac243f961e69215644eadb2e9ff9f0f16eb92 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 10 Nov 2008 13:37:07 +0000 Subject: [PATCH] Backup eingearbeitet git-svn-id: http://svn.brehm-online.com/svn/my-stuff/postfix@28 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- get-lookup-tables.conf | 1 + get-lookup-tables.pl | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/get-lookup-tables.conf b/get-lookup-tables.conf index 0398c2a..f03099a 100644 --- a/get-lookup-tables.conf +++ b/get-lookup-tables.conf @@ -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 # diff --git a/get-lookup-tables.pl b/get-lookup-tables.pl index 76fc200..fe0e172 100755 --- a/get-lookup-tables.pl +++ b/get-lookup-tables.pl @@ -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}; -- 2.39.5