diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Conf.cc | 12 | ||||
-rw-r--r-- | src/Conf.h | 4 | ||||
-rw-r--r-- | src/ConfBase.cc | 12 | ||||
-rw-r--r-- | src/ConfBase.h | 12 | ||||
-rw-r--r-- | src/ConfDirective.cc | 68 | ||||
-rw-r--r-- | src/ConfDirective.h | 6 | ||||
-rw-r--r-- | src/DeviceAccess.cc | 4 | ||||
-rw-r--r-- | src/MakeBackup.cc | 24 |
8 files changed, 86 insertions, 56 deletions
diff --git a/src/Conf.cc b/src/Conf.cc index f58e910..521fb7f 100644 --- a/src/Conf.cc +++ b/src/Conf.cc @@ -92,15 +92,15 @@ void Conf::write(std::ostream &os, int step, bool verbose) const { d(os, "", step); d(os, "# Command to run before accessing backup devices", step); - d(os, "# pre-access-hook COMMAND ...", step); - if(preAccess.size()) - os << indent(step) << "pre-access-hook " << quote(preAccess) << '\n'; + d(os, "# pre-device-hook COMMAND ...", step); + if(preDevice.size()) + os << indent(step) << "pre-device-hook " << quote(preDevice) << '\n'; d(os, "", step); d(os, "# Command to run after accessing backup devices", step); - d(os, "# pre-access-hook COMMAND ...", step); - if(postAccess.size()) - os << indent(step) << "post-access-hook " << quote(postAccess) << '\n'; + d(os, "# pre-device-hook COMMAND ...", step); + if(postDevice.size()) + os << indent(step) << "post-device-hook " << quote(postDevice) << '\n'; d(os, "", step); d(os, "# Names of backup devices", step); @@ -122,10 +122,10 @@ public: std::string sendmail = DEFAULT_SENDMAIL; /** @brief Pre-access hook */ - std::vector<std::string> preAccess; + std::vector<std::string> preDevice; /** @brief Post-access hook */ - std::vector<std::string> postAccess; + std::vector<std::string> postDevice; /** @brief Path to stylesheet for HTML report output * diff --git a/src/ConfBase.cc b/src/ConfBase.cc index 8025d5e..d58fb0f 100644 --- a/src/ConfBase.cc +++ b/src/ConfBase.cc @@ -114,15 +114,15 @@ void ConfBase::write(std::ostream &os, int step, bool verbose) const { d(os, "", 0); d(os, "# Command to run prior to making a backup", step); - d(os, "# pre-backup-hook COMMAND ...", step); - if(preBackup.size()) - os << indent(step) << "pre-backup-hook " << quote(preBackup) << '\n'; + d(os, "# pre-volume-hook COMMAND ...", step); + if(preVolume.size()) + os << indent(step) << "pre-volume-hook " << quote(preVolume) << '\n'; d(os, "", 0); d(os, "# Command to run after making a backup", step); - d(os, "# post-backup-hook COMMAND ...", step); - if(postBackup.size()) - os << indent(step) << "post-backup-hook " << quote(postBackup) << '\n'; + d(os, "# post-volume-hook COMMAND ...", step); + if(postVolume.size()) + os << indent(step) << "post-volume-hook " << quote(postVolume) << '\n'; d(os, "", 0); d(os, "# Maximum time to wait for rsync to complete", step); diff --git a/src/ConfBase.h b/src/ConfBase.h index 09bce59..2e58c21 100644 --- a/src/ConfBase.h +++ b/src/ConfBase.h @@ -50,8 +50,8 @@ public: maxAge(parent->maxAge), backupPolicy(parent->backupPolicy), backupParameters(parent->backupParameters), prunePolicy(parent->prunePolicy), - pruneParameters(parent->pruneParameters), preBackup(parent->preBackup), - postBackup(parent->postBackup), rsyncTimeout(parent->rsyncTimeout), + pruneParameters(parent->pruneParameters), preVolume(parent->preVolume), + postVolume(parent->postVolume), rsyncTimeout(parent->rsyncTimeout), rsyncCommand(parent->rsyncCommand), rsyncBaseOptions(parent->rsyncBaseOptions), rsyncExtraOptions(parent->rsyncExtraOptions), @@ -77,11 +77,11 @@ public: /** @brief Pruning policy parameters */ std::map<std::string, std::string> pruneParameters; - /** @brief Pre-backup hook */ - std::vector<std::string> preBackup; + /** @brief Pre-volume hook */ + std::vector<std::string> preVolume; - /** @brief Post-backup hook */ - std::vector<std::string> postBackup; + /** @brief Post-volume hook */ + std::vector<std::string> postVolume; /** @brief rsync timeout */ int rsyncTimeout = 0; diff --git a/src/ConfDirective.cc b/src/ConfDirective.cc index 57f8eb8..e1e7c10 100644 --- a/src/ConfDirective.cc +++ b/src/ConfDirective.cc @@ -34,10 +34,21 @@ ConfDirective::ConfDirective(const char *name_, int min_, int max_, max(max_) { if(!directives) directives = new directives_type(); + if(!aliases) + aliases = new std::set<std::string>(); assert((*directives).find(name) == (*directives).end()); (*directives)[name] = this; } +void ConfDirective::alias(const char *name_) { + std::string n(name_); + assert(directives != nullptr); + assert((*directives).find(n) == (*directives).end()); + (*directives)[n] = this; + assert(aliases != nullptr); + aliases->insert(n); +} + const ConfDirective *ConfDirective::find(const std::string &name) { auto it = directives->find(name); return it == directives->end() ? nullptr : it->second; @@ -49,6 +60,10 @@ void ConfDirective::check(const ConfContext &cc) const { throw SyntaxError("too few arguments to '" + name + "'"); if(args > max) throw SyntaxError("too many arguments to '" + name + "'"); + if(aliases->find(cc.bits[0]) != aliases->end()) + warning(WARNING_DEPRECATED, + "%s:%d: the '%s' directive is deprecated, use '%s' instead", + cc.path.c_str(), cc.line, cc.bits[0].c_str(), name.c_str()); } bool ConfDirective::get_boolean(const ConfContext &cc) const { @@ -74,6 +89,7 @@ void ConfDirective::extend(const ConfContext &cc, } directives_type *ConfDirective::directives; +std::set<std::string> *ConfDirective::aliases; // HostOnlyDirective ---------------------------------------------------------- @@ -268,21 +284,25 @@ static const struct SendmailDirective: public ConfDirective { } } sendmail_directive; -/** @brief The @c pre-access-hook directive */ -static const struct PreAccessHookDirective: public ConfDirective { - PreAccessHookDirective(): ConfDirective("pre-access-hook", 1, INT_MAX) {} +/** @brief The @c pre-device-hook directive */ +static const struct PreDeviceHookDirective: public ConfDirective { + PreDeviceHookDirective(): ConfDirective("pre-device-hook", 1, INT_MAX) { + alias("pre-access-hook"); + } void set(ConfContext &cc) const override { - cc.conf->preAccess.assign(cc.bits.begin() + 1, cc.bits.end()); + cc.conf->preDevice.assign(cc.bits.begin() + 1, cc.bits.end()); } -} pre_access_hook_directive; +} pre_device_hook_directive; -/** @brief The @c post-access-hook directive */ -static const struct PostAccessHookDirective: public ConfDirective { - PostAccessHookDirective(): ConfDirective("post-access-hook", 1, INT_MAX) {} +/** @brief The @c post-device-hook directive */ +static const struct PostDeviceHookDirective: public ConfDirective { + PostDeviceHookDirective(): ConfDirective("post-device-hook", 1, INT_MAX) { + alias("post-access-hook"); + } void set(ConfContext &cc) const override { - cc.conf->postAccess.assign(cc.bits.begin() + 1, cc.bits.end()); + cc.conf->postDevice.assign(cc.bits.begin() + 1, cc.bits.end()); } -} post_access_hook_directive; +} device; /** @brief The @c keep-prune-logs directive */ static const struct KeepPruneLogsDirective: public ConfDirective { @@ -545,23 +565,27 @@ static const struct PruneParameterDirective: InheritableDirective { } } prune_parameter_directive; -/** @brief The @c pre-backup-hook directive */ -static const struct PreBackupHookDirective: InheritableDirective { - PreBackupHookDirective(): - InheritableDirective("pre-backup-hook", 1, INT_MAX) {} +/** @brief The @c pre-volume-hook directive */ +static const struct PreVolumeHookDirective: InheritableDirective { + PreVolumeHookDirective(): + InheritableDirective("pre-volume-hook", 1, INT_MAX) { + alias("pre-backup-hook"); + } void set(ConfContext &cc) const override { - cc.context->preBackup.assign(cc.bits.begin() + 1, cc.bits.end()); + cc.context->preVolume.assign(cc.bits.begin() + 1, cc.bits.end()); } -} pre_backup_hook_directive; +} pre_volume_hook_directive; -/** @brief The @c post-backup-hook directive */ -static const struct PostBackupHookDirective: InheritableDirective { - PostBackupHookDirective(): - InheritableDirective("post-backup-hook", 1, INT_MAX) {} +/** @brief The @c post-volume-hook directive */ +static const struct PostVolumeHookDirective: InheritableDirective { + PostVolumeHookDirective(): + InheritableDirective("post-volume-hook", 1, INT_MAX) { + alias("post-backup-hook"); + } void set(ConfContext &cc) const override { - cc.context->postBackup.assign(cc.bits.begin() + 1, cc.bits.end()); + cc.context->postVolume.assign(cc.bits.begin() + 1, cc.bits.end()); } -} post_backup_hook_directive; +} post_volume_hook_directive; /** @brief The @c rsync-timeout directive */ static const struct RsyncTimeoutDirective: InheritableDirective { diff --git a/src/ConfDirective.h b/src/ConfDirective.h index 7e4a752..b951ac4 100644 --- a/src/ConfDirective.h +++ b/src/ConfDirective.h @@ -98,6 +98,9 @@ public: unsigned acceptable_levels_ = LEVEL_TOP, unsigned new_level_ = 0); + /** @brief Add an alias */ + void alias(const char *name_); + /** @brief Name of directive */ const std::string name; @@ -149,6 +152,9 @@ private: /** @brief Map names to directives */ static directives_type *directives; + + /** @brief Deprecated aliases */ + static std::set<std::string> *aliases; }; /** @brief Base class for generally inheritable directives */ diff --git a/src/DeviceAccess.cc b/src/DeviceAccess.cc index 13307cb..b56cd30 100644 --- a/src/DeviceAccess.cc +++ b/src/DeviceAccess.cc @@ -45,7 +45,7 @@ static void runDeviceAccessHook(const std::vector<std::string> &cmd, void preDeviceAccess() { if(!devicesReady) { - runDeviceAccessHook(globalConfig.preAccess, "pre-access-hook"); + runDeviceAccessHook(globalConfig.preDevice, "pre-device-hook"); devicesReady = true; } } @@ -57,7 +57,7 @@ void closeOnUnmount(IO *f) { void postDeviceAccess() { if(devicesReady) { deleteAll(filesToClose); - runDeviceAccessHook(globalConfig.postAccess, "post-access-hook"); + runDeviceAccessHook(globalConfig.postDevice, "post-device-hook"); devicesReady = false; } } diff --git a/src/MakeBackup.cc b/src/MakeBackup.cc index a2d11ea..d97dac5 100644 --- a/src/MakeBackup.cc +++ b/src/MakeBackup.cc @@ -130,7 +130,7 @@ public: */ void subprocessIO(Subprocess &sp, bool outputToo = true); - /** @brief Run the pre-backup hook if there is one + /** @brief Run the pre-volume hook if there is one * @return Wait status */ int preBackup(); @@ -140,7 +140,7 @@ public: */ int rsyncBackup(); - /** @brief Run the post-backup hook if there is one */ + /** @brief Run the post-volume hook if there is one */ void postBackup(); /** @brief Perform a backup */ @@ -203,16 +203,16 @@ void MakeBackup::subprocessIO(Subprocess &sp, bool outputToo) { } int MakeBackup::preBackup() { - if(volume->preBackup.size()) { + if(volume->preVolume.size()) { EventLoop e; ActionList al(&e); std::string output; - Subprocess sp("pre-backup-hook/" + volume->parent->name + "/" + volume->name + Subprocess sp("pre-volume-hook/" + volume->parent->name + "/" + volume->name + "/" + device->name, - volume->preBackup); + volume->preVolume); sp.capture(1, &output); - sp.setenv("RSBACKUP_HOOK", "pre-backup-hook"); + sp.setenv("RSBACKUP_HOOK", "pre-volume-hook"); setEnvironment(sp); sp.setTimeout(volume->hookTimeout); sp.reporting(globalWarningMask & WARNING_VERBOSE, false); @@ -344,15 +344,15 @@ int MakeBackup::rsyncBackup() { } void MakeBackup::postBackup() { - if(volume->postBackup.size()) { + if(volume->postVolume.size()) { EventLoop e; ActionList al(&e); - Subprocess sp("post-backup-hook/" + volume->parent->name + "/" + Subprocess sp("post-volume-hook/" + volume->parent->name + "/" + volume->name + "/" + device->name, - volume->postBackup); + volume->postVolume); sp.setenv("RSBACKUP_STATUS", outcome && outcome->rc == 0 ? "ok" : "failed"); - sp.setenv("RSBACKUP_HOOK", "post-backup-hook"); + sp.setenv("RSBACKUP_HOOK", "post-volume-hook"); setEnvironment(sp); sp.setTimeout(volume->hookTimeout); sp.reporting(globalWarningMask & WARNING_VERBOSE, false); @@ -364,12 +364,12 @@ void MakeBackup::postBackup() { void MakeBackup::performBackup() { // Run the pre-backup hook - what = "preBackup"; + what = "preVolume"; int rc = preBackup(); if(WIFEXITED(rc) && WEXITSTATUS(rc) == EX_TEMPFAIL) { if(globalWarningMask & WARNING_VERBOSE) IO::out.writef( - "INFO: %s:%s is temporarily unavailable due to pre-backup-hook\n", + "INFO: %s:%s is temporarily unavailable due to pre-volume-hook\n", host->name.c_str(), volume->name.c_str()); return; } |