[pmg-devel] [PATCH pmg-api] backup: add SA custom score file to backup

Stoiko Ivanov s.ivanov at proxmox.com
Tue Nov 10 18:56:35 CET 2020


/etc/mail/spamassassin/pmg-scores.cf contains the custom scores users can
set via GUI. It should be included in the backup (and restored if present).

Reported via our community forum:
https://forum.proxmox.com/threads/backup-restore-bug.78605/

Tested on my local setup by creating a bogus score, creating a backup,
removing the pmg-scores file and restoring the backup.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/Backup.pm | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/PMG/Backup.pm b/src/PMG/Backup.pm
index e77f67c..275fa12 100644
--- a/src/PMG/Backup.pm
+++ b/src/PMG/Backup.pm
@@ -13,7 +13,10 @@ use PMG::pmgcfg;
 use PMG::AtomicFile;
 use PMG::Utils qw(postgres_admin_cmd);
 
-my $sa_custom_config_fn = "/etc/mail/spamassassin/custom.cf";
+my $sa_configs = [
+    "/etc/mail/spamassassin/custom.cf",
+    "/etc/mail/spamassassin/pmg-scores.cf",
+];
 
 sub get_restore_options {
     return (
@@ -202,7 +205,7 @@ sub pmg_backup {
 
 	my $extra_cfgs =  [];
 
-	push @$extra_cfgs, $sa_custom_config_fn;
+	push @$extra_cfgs, @{$sa_configs};
 
 	my $extradb = $include_statistics ? $statfn : '';
 
@@ -308,10 +311,12 @@ sub pmg_restore {
 	    system("cp -a $dirname/config/etc/pmg/* /etc/pmg/") == 0 ||
 		die "unable to restore system configuration: ERROR";
 
-	    if (-f "$dirname/config/${sa_custom_config_fn}") {
-		my $data = PVE::Tools::file_get_contents(
-		    "$dirname/config/${sa_custom_config_fn}", 1024*1024);
-		PVE::Tools::file_set_contents($sa_custom_config_fn, $data);
+	    for my $sa_cfg (@{$sa_configs}) {
+		if (-f "$dirname/config/${sa_cfg}") {
+		    my $data = PVE::Tools::file_get_contents(
+			"$dirname/config/${sa_cfg}", 1024*1024);
+		    PVE::Tools::file_set_contents($sa_cfg, $data);
+		}
 	    }
 
 	    my $cfg = PMG::Config->new();
-- 
2.20.1





More information about the pmg-devel mailing list