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


Description: Add the possibilty to run a script before/after the NightlyRun.
Author: Tobias Frost <t...@debian.org>
---
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",

Attachment: signature.asc
Description: This is a digitally signed message part

------------------------------------------------------------------------------
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
BackupPC-devel@lists.sourceforge.net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-devel
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/

Reply via email to