BackupPPC: Patch for an extra callback for NightlyRun

Tobias Frost <[email protected]> Fri, 02 Jan 2015 10:03:55 +0100
Newsgroups gmane.comp.sysutils.backup.backuppc.devel
Message-ID <[email protected]>
Hi everyone,

Here's a small patch against 3.3.0 which enhances BackupPC callback
methods for nightly jobs: It adds the possiblity to call those jobs,
NightlyPreUserCmd
NightlyPostUserCmd
, called before and after the NightlyRun. 

(My use-case is that I have flashcache running on the Pool's partition
and to avoid cache-poisoning by the NightlyJobs I deactivate caching
during backup and nightly-jobs. I can provide those scripts on request,
just email me.) 

(Craig: 10000's of Kudos for coding BackupPPC)

--
tobi

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net

_______________________________________________
BackupPC-devel mailing list
[email protected]
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-devel
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/
nighly-hook.patch (text/x-patch, 3.9 KB)
Description: Add the possibilty to run a script before/after the NightlyRun.
Author: Tobias Frost <[email protected]>
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/bin/BackupPC_nightly
+++ b/bin/BackupPC_nightly
@@ -114,6 +114,13 @@
     eval($reply);
 }
 
+
+UserCommandRun("NightlyPreUserCmd");
+if ( $? && $Conf{UserCmdCheckStatus} ) {
+    print("NightlyPreUserCmd returned error status $?\n");
+    exit(1);
+}
+
 ###########################################################################
 # Get statistics on the pool, and remove files that have only one link.
 ###########################################################################
@@ -232,6 +239,11 @@
     doBackupInfoUpdate();
 }
 
+UserCommandRun("NightlyPostUserCmd");
+if ( $? && $Conf{UserCmdCheckStatus} ) {
+    print("NightlyPostUserCmd returned error status $?\n");
+}
+
 #
 # Update the backupInfo files based on the backups file.
 # We do this just once a week (on Sun) since it is only
@@ -328,3 +340,50 @@
         unlink($f->{path});
     }
 }
+
+# Run an optional pre- or post-dump command
+#
+sub UserCommandRun
+{
+    my($cmdType) = @_;
+    my($pid) = $$;
+
+    return if ( !defined($Conf{$cmdType}) );
+    my $vars = {
+#        xfer         => $xfer,
+#        client       => $client,
+#        host         => $host,
+#        user         => $user,
+#        share        => $ArchiveReq{shareDest},
+#        XferMethod   => $Conf{XferMethod},
+#        HostList     => \@{$ArchiveReq{HostList}},
+#        BackupList   => \@{$ArchiveReq{BackupList}},
+#        archiveloc   => $ArchiveReq{archiveloc},
+#        parfile      => $ArchiveReq{parfile},
+#        compression  => $ArchiveReq{compression},
+#        compext      => $ArchiveReq{compext},
+#        splitsize    => $ArchiveReq{splitsize},
+#        sshPath      => $Conf{SshPath},
+        LOG          => *LOG,
+#        XferLOG      => $ArchiveLOG,
+#        stat         => \%stat,
+#        xferOK       => $stat{xferOK} || 0,
+#        type         => "archive",
+        cmdType      => $cmdType,
+	pid => $$,
+    };
+    my $cmd = $bpc->cmdVarSubstitute($Conf{$cmdType}, $vars);
+    print("Executing $cmdType: @$cmd Pid: $pid \n");
+    #
+    # Run the user's command, dumping the stdout/stderr into the
+    # Xfer log file.  Also supply the optional $vars and %Conf in
+    # case the command is really perl code instead of a shell
+    # command.
+    #
+    $bpc->cmdSystemOrEval($cmd,
+            sub {
+		print(LOG $bpc->timeStamp, "Output from $cmdType: ", $_[0]);
+            },
+            $vars, \%Conf);
+}
+
--- a/lib/BackupPC/CGI/EditConfig.pm
+++ b/lib/BackupPC/CGI/EditConfig.pm
@@ -356,6 +356,8 @@
 	    {name => "RestorePostUserCmd"},
 	    {name => "ArchivePreUserCmd"},
 	    {name => "ArchivePostUserCmd"},
+	    {name => "NightlyPreUserCmd"},
+	    {name => "NightlyPostUserCmd"},
 	    {name => "UserCmdCheckStatus"},
 	],
     },
--- a/lib/BackupPC/Config/Meta.pm
+++ b/lib/BackupPC/Config/Meta.pm
@@ -320,6 +320,8 @@
     RestorePostUserCmd	=> {type => "string", undefIfEmpty => 1},
     ArchivePreUserCmd	=> {type => "string", undefIfEmpty => 1},
     ArchivePostUserCmd	=> {type => "string", undefIfEmpty => 1},
+    NightlyPreUserCmd	=> {type => "string", undefIfEmpty => 1},
+    NightlyPostUserCmd	=> {type => "string", undefIfEmpty => 1},
     UserCmdCheckStatus  => "boolean",
 
     ClientNameAlias 	=> {type => "string", undefIfEmpty => 1},
@@ -476,6 +478,8 @@
                 ArchivePostUserCmd        => "boolean",
                 DumpPostShareCmd          => "boolean",
                 DumpPreShareCmd           => "boolean",
+                NightlyPreUserCmd         => "boolean",
+                NightlyPostUserCmd        => "boolean",
                 UserCmdCheckStatus        => "boolean",
                 EMailNotifyMinDays        => "boolean",
                 EMailFromUserName         => "boolean",
signature.asc (application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAABCAAGBQJUpl8AAAoJEJFk+h0XvV02gDgQANKwY0zwv1NVFdDBmIU3J8bf
qasV5wba3qcU1m9A28EJG+tCaGdBDJHOmE6vKTWwJgKDBbap4HL5SNTwugCGVqu6
ugc/e0UwR0L5LGu2RFOJBVTEUeB02S0ZMJ4C+Tl/5GlOZJ2zQQT9nW5mmZuwXjLh
47rAg4D0peYa5CmOiM+y9KVRggR5Af4EFAK+VonEc+bSdFikSAqsKxzlkG36iqha
n5PgayEC9Yknm6kcPOeVSHqJRNI1kdiSU/Fuodg/h2xCKAFWy8yHi2U5Q+qrwhFN
yo361TqyDhvgeyugv+4JmKHJPqClY9dsFmAjM34KNkKBimFNB7TxwSiL0h1yGc2e
3oZjDjL9vYWQ194xKIWnmWF6eGBxCd5FyP4VHcOCx9348cCluVtkHeiCCXNXOHHw
8Mt9aqIiF1iE+60tMVWL/DHmtxiZFKk2sYjH+HxacXTP0emyQ/Hrbvatl0WGdDTm
uT5+XfuA6DTlVEcsg4LQ9qRc5wvcEYDyn87T5uEyreEAiYpuZKbwphL3axON5HEF
EU3eILJALmx20bwTyvyvYpYyHBlpDA8QGMKO/bpcxMqoAd7vO2gQLcwfsKN8GDKh
T/aaRv4VzdhXzMYpmklZckR9IiJAGptEq3GoEUmt7YZwVR+lNf2pwOWFctxhqlad
JBxOY2Nef5uQ2biaVNS7
=Gd7A
-----END PGP SIGNATURE-----