};
my $workdir = catfile( '', 'etc', 'postfix', 'work' );
+my $backup_dir = catfile( '', 'etc', 'postfix', '.old' );
my $lookup_dir = $postfix_dir;
my $default_database_type = 'hash';
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 ) {
close FILE;
+ $backup_file .= "." . curtime(1);
+
my $changed = 0;
$changed = 1 unless -f $cur_file;
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'};
#--------------------------------------------------------------------------------------
-=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;
}
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};