From d3c059638819f2182a7b2feb601c8496dee97ee8 Mon Sep 17 00:00:00 2001 From: Yannis Gerlach <100762533+ygerlach@users.noreply.github.com> Date: Fri, 31 Oct 2025 17:25:58 +0100 Subject: [PATCH] trigger backup hooks after rsync snapshots --- src/Core/Main.vala | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Core/Main.vala b/src/Core/Main.vala index 6bd8c83..ec8d841 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -1690,6 +1690,9 @@ public class Main : GLib.Object{ set_tags(snapshot); // set_tags() will update the control file + // Perform any post-backup actions + this.run_post_backup_hooks(snapshot_path); + return snapshot; } @@ -1781,18 +1784,27 @@ public class Main : GLib.Object{ set_tags(snapshot); // set_tags() will update the control file // Perform any post-backup actions - log_debug("Running post-backup tasks..."); - - string sh = "test -d \"/etc/timeshift/backup-hooks.d\" &&" + - " export TS_SNAPSHOT_PATH=\"" + snapshot_path + "\" &&" + - " run-parts --verbose /etc/timeshift/backup-hooks.d"; - exec_script_sync(sh, null, null, false, false, false, true); - - log_debug("Finished running post-backup tasks..."); + this.run_post_backup_hooks(snapshot_path); return snapshot; } + private void run_post_backup_hooks(string snapshot_path) { + const string backuphooksdir = "/etc/timeshift/backup-hooks.d"; + FileType fileType = File.new_for_path(backuphooksdir).query_file_type(FileQueryInfoFlags.NONE); + if(fileType == FileType.DIRECTORY) { + log_debug("Running post-backup tasks..."); + + string sh = "export TS_SNAPSHOT_PATH=\"" + snapshot_path + "\" &&" + + " run-parts --verbose \"%s\"".printf(backuphooksdir); + exec_script_sync(sh, null, null, false, false, false, true); + + log_debug("Finished running post-backup tasks..."); + } else { + log_debug("Backup hooks skipped, because %s does not exist".printf(backuphooksdir)); + } + } + private void set_tags(Snapshot snapshot){ // add tags passed on commandline for both --check and --create