Created
December 14, 2014 10:49
-
-
Save coldtobi/8f5556a4c0f5e1d38125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment