]> git.proxmox.com Git - pmg-api.git/commitdiff
backup: add SA custom score file to backup
authorStoiko Ivanov <s.ivanov@proxmox.com>
Tue, 10 Nov 2020 17:56:35 +0000 (18:56 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 18 Nov 2020 07:11:08 +0000 (08:11 +0100)
/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@proxmox.com>
src/PMG/Backup.pm

index e77f67cdb6b4f6f2e0989b0812ae8e0ad3deb73f..275fa1208850e3b02e8c81a9c8d175f7dda02604 100644 (file)
@@ -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();