tachtler:postfix_amavis_mailzu_installieren
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | Nächste ÜberarbeitungBeide Seiten der Revision | ||
tachtler:postfix_amavis_mailzu_installieren [2013/12/08 10:01] – [Postfix AMaViS MailZu Konfiguration AMaViS] klaus | tachtler:postfix_amavis_mailzu_installieren [2013/12/08 10:19] – [Postfix AMaViS MailZu Datenbank Bereinigung] klaus | ||
---|---|---|---|
Zeile 673: | Zeile 673: | ||
gekennzeichnet sind: | gekennzeichnet sind: | ||
- | Hier de notwendigen Konfigurationen von **''/ | + | Hier de notwendigen Konfigurationen von **''/ |
<code perl> | <code perl> | ||
# | # | ||
- | # Tachtler | ||
- | # default: # | ||
use strict; | use strict; | ||
Zeile 695: | Zeile 693: | ||
' | ' | ||
); | ); | ||
- | |||
# Set this to 1 if you are using the new database schema | # Set this to 1 if you are using the new database schema | ||
Zeile 701: | Zeile 698: | ||
# have the foreign key references between the tables and use | # have the foreign key references between the tables and use | ||
# time_iso as a real date type instead of a string. | # time_iso as a real date type instead of a string. | ||
+ | # Tachtler | ||
+ | # default: my($new_dd) = 1; # 1 or undef | ||
my($new_dd) = undef; # 1 or undef | my($new_dd) = undef; # 1 or undef | ||
Zeile 720: | Zeile 719: | ||
# MySQL | # MySQL | ||
# Tachtler | # Tachtler | ||
+ | # default: # | ||
+ | # default: # | ||
my($new_interval) = '7 day'; | my($new_interval) = '7 day'; | ||
my($new_partial_interval) = '1 hour'; | my($new_partial_interval) = '1 hour'; | ||
Zeile 729: | Zeile 730: | ||
##### END OF CONFIGURATION SECTION ###### | ##### END OF CONFIGURATION SECTION ###### | ||
- | ... | ||
- | </ | ||
- | Der Aufruf des Scripts, welches ein Perl-Script ist, muss mit einem Parameter für die Angabe des Datenbank-Typs, hier [[http://www.mysql.de/|MySQL]] erfolgen, was auch eine Abfrage wie nachfolgend dargestellt zeigt: | + | # Options array |
- | <code> | + | my(%opt); |
- | # / | + | |
- | Usage: | + | my(@modules); |
- | | + | my(@missing); |
- | | + | |
+ | my(@dsn) = split(/:/,$storage_sql_dsn[0],-1); | ||
+ | push(@modules, ' | ||
+ | |||
+ | for my $m (@modules) { | ||
+ | local($_) = $m; | ||
+ | $_ .= /^auto::/ ? '.al' : '.pm' | ||
+ | s[::][/]g; | ||
+ | eval { require $_ } or push(@missing, $m); | ||
+ | } | ||
+ | |||
+ | die "ERROR: MISSING module(s): | ||
+ | |||
+ | sub build_queries($) { | ||
+ | my($dbtype) = shift; | ||
+ | # Return a hash of queries to be run | ||
+ | my(%query) = ( | ||
+ | # Old schema queries | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | " | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | " | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | # New schema queries | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | # Generic queries | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | ); | ||
+ | |||
+ | if ($dbtype eq ' | ||
+ | $query{' | ||
+ | # New schema queries | ||
+ | $query{' | ||
+ | ' | ||
+ | " | ||
+ | | ||
+ | ' | ||
+ | " | ||
+ | ' | ||
+ | } | ||
+ | |||
+ | if ($dbtype eq ' | ||
+ | # New schema queries | ||
+ | $query{' | ||
+ | ' | ||
+ | " | ||
+ | $query{' | ||
+ | ' | ||
+ | " | ||
+ | ' | ||
+ | |||
+ | # Old schema queries | ||
+ | $query{' | ||
+ | 'LEFT JOIN msgrcpt USING(mail_id) ' . | ||
+ | 'WHERE msgrcpt.mail_id IS NULL'; | ||
+ | $query{' | ||
+ | ' | ||
+ | ' | ||
+ | $query{' | ||
+ | 'LEFT JOIN msgs USING(mail_id) ' . | ||
+ | 'WHERE msgs.mail_id IS NULL'; | ||
+ | } | ||
+ | |||
+ | my(%post_query) = ( | ||
+ | ' | ||
+ | ); | ||
+ | |||
+ | # Order of execution IS IMPORTANT! | ||
+ | my(@query_order) = qw (del_d_flag del_partial_msg del_msgs_mail_ids | ||
+ | | ||
+ | | ||
+ | ); | ||
+ | |||
+ | @query_order = qw (del_d_flag_new del_partial_msg_new | ||
+ | | ||
+ | ) if $new_dd; | ||
+ | |||
+ | my(@post_query_order); | ||
+ | push(@post_query_order, | ||
+ | |||
+ | return (\%query, | ||
+ | } | ||
+ | |||
+ | |||
+ | sub usage { | ||
+ | print "Usage:\n"; | ||
+ | print " | ||
+ | print " | ||
+ | print "\tThe database configuration parameter is REQUIRED!\n\n"; | ||
+ | print " | ||
+ | "\tand ' | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | sub main { | ||
+ | Getopt:: | ||
+ | GetOptions(\%opt, | ||
+ | ) or exit(1); | ||
+ | usage if $opt{help}; | ||
+ | usage if not $opt{database}; | ||
+ | my($dbh) = connect_to_sql(@storage_sql_dsn); | ||
+ | my($query, | ||
+ | my($sth_ref) = prepare_queries($dbh, | ||
+ | my($result) = exec_queries($dbh, | ||
+ | | ||
+ | ); | ||
+ | print " | ||
+ | $dbh-> | ||
+ | } | ||
+ | |||
+ | sub exec_queries($$$$$) { | ||
+ | my($dbh, | ||
+ | my($affected); | ||
+ | |||
+ | $dbh-> | ||
+ | eval { | ||
+ | foreach (@$query_o) { | ||
+ | if ($opt{verbose}) { | ||
+ | print " | ||
+ | print $query-> | ||
+ | } | ||
+ | $affected = $sth_ref-> | ||
+ | print " | ||
+ | } | ||
+ | }; | ||
+ | if ($@ ne '' | ||
+ | $dbh-> | ||
+ | print "There was an error executing a query! $@\n" . | ||
+ | "No records modified by database maintenance\n" | ||
+ | " | ||
+ | return undef | ||
+ | } else { | ||
+ | $dbh-> | ||
+ | } | ||
+ | |||
+ | eval { | ||
+ | foreach (@$p_query_o) { | ||
+ | if ($opt{verbose}) { | ||
+ | print " | ||
+ | print $p_query-> | ||
+ | } | ||
+ | $affected = $sth_ref-> | ||
+ | print " | ||
+ | } | ||
+ | }; | ||
+ | if ($@ ne '' | ||
+ | print "There was an error executing an optional query! $@\n" . | ||
+ | return undef | ||
+ | } | ||
+ | |||
+ | return 1; | ||
+ | |||
+ | } | ||
+ | |||
+ | sub connect_to_sql(@) { | ||
+ | my(@sql_dsn) = @_; | ||
+ | my($dsn, $username, $password) = @sql_dsn; | ||
+ | print " | ||
+ | print " | ||
+ | my($dbh) = DBI-> | ||
+ | # | ||
+ | | ||
+ | if ($dbh) { | ||
+ | print " | ||
+ | } else { | ||
+ | die " | ||
+ | } | ||
+ | $dbh; | ||
+ | } | ||
- | The database configuration parameter is REQUIRED! | + | sub prepare_queries($$$) { |
+ | my($dbh) = shift; | ||
+ | my($query) = shift; | ||
+ | my($p_query) = shift; | ||
+ | my(%sths); | ||
+ | foreach my $query_set ($query, $p_query) { | ||
+ | foreach (keys %$query) { | ||
+ | $sths{$_} = $dbh-> | ||
+ | } | ||
+ | } | ||
+ | \%sths | ||
+ | } | ||
- | Possible parameters for the ' | + | main; |
- | and ' | + | |
</ | </ | ||
tachtler/postfix_amavis_mailzu_installieren.txt · Zuletzt geändert: 2013/12/08 10:30 von klaus