From 84501c05940a7ed60f5bb3cc81e244b9a7fe01b1 Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Wed, 1 Jan 2025 21:41:17 +0100 Subject: [PATCH 01/10] #365 btrfs hooks --- src/Core/Main.vala | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Core/Main.vala b/src/Core/Main.vala index a47a3ae..09844bc 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -1693,6 +1693,16 @@ 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 = "if [ -d \"/etc/timeshift/backup-hooks.d\" ]; then \n"; + sh += " run-parts --verbose /etc/timeshift/backup-hooks.d \n"; + sh += "fi \n"; + exec_script_sync(sh, null, null, false, false, false, true); + + log_debug("Finished running post-backup tasks..."); + return snapshot; } @@ -3032,6 +3042,16 @@ public class Main : GLib.Object{ log_msg(_("Restore completed")); thr_success = true; + + // Perform any post-restore actions + log_debug("Running post-restore tasks..."); + + string sh += "if [ -d \"/etc/timeshift/restore-hooks.d\" ]; then \n"; + sh += " run-parts --verbose /etc/timeshift/restore-hooks.d \n"; + sh += "fi \n"; + + exec_script_sync(sh, null, null, false, false, false, true); + log_debug("Finished running post-restore tasks..."); if (restore_current_system){ log_msg(_("Snapshot will become active after system is rebooted.")); From 890729e04021903b1ee1228056f81d108a6df305 Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Wed, 1 Jan 2025 22:03:39 +0100 Subject: [PATCH 02/10] #365 fix compilation issue --- src/Core/Main.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Main.vala b/src/Core/Main.vala index 09844bc..3a883e4 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -3046,7 +3046,7 @@ public class Main : GLib.Object{ // Perform any post-restore actions log_debug("Running post-restore tasks..."); - string sh += "if [ -d \"/etc/timeshift/restore-hooks.d\" ]; then \n"; + string sh = "if [ -d \"/etc/timeshift/restore-hooks.d\" ]; then \n"; sh += " run-parts --verbose /etc/timeshift/restore-hooks.d \n"; sh += "fi \n"; From a35354662d1d1ab36ab136a213984231801526f2 Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Thu, 2 Jan 2025 09:09:35 +0100 Subject: [PATCH 03/10] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5fb5597..be5bbfd 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ You can selectively include items for backup from the ***Settings*** window. Sel - **@** and **@home** subvolumes may be on same or different BTRFS volumes - **@** may be on BTRFS volume and **/home** may be mounted on non-BTRFS partition - If swap files are used they should not be located in **@** or **@home** and could instead be stored in their own subvolume, eg **@swap** + - Separate partitions (e.g. `/boot`) can be handled via custom created hooks (placed in `/etc/timeshift/backup-hooks.d/` and `/etc/timeshift/restore-hooks.d/`) - Other layouts are not supported - Make sure, that you have selected subvolume *@* or */@* for root. You can check that executing script below, and if output is *OK*, then everything is alright. From f90902a21f0c7c2f874036ea13c3dd467b1ba593 Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Mon, 6 Jan 2025 10:38:18 +0100 Subject: [PATCH 04/10] #365 refactor shell test Co-authored-by: Yannis Gerlach <100762533+ygerlach@users.noreply.github.com> --- src/Core/Main.vala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Core/Main.vala b/src/Core/Main.vala index 3a883e4..e3b2e6e 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -1696,9 +1696,8 @@ public class Main : GLib.Object{ // Perform any post-backup actions log_debug("Running post-backup tasks..."); - string sh = "if [ -d \"/etc/timeshift/backup-hooks.d\" ]; then \n"; - sh += " run-parts --verbose /etc/timeshift/backup-hooks.d \n"; - sh += "fi \n"; + string sh = "test -d \"/etc/timeshift/backup-hooks.d\" &&" + " 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..."); From 332f1f1c80923551eb711f27c506d243168211fa Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Mon, 6 Jan 2025 10:38:33 +0100 Subject: [PATCH 05/10] #365 refactor shell test Co-authored-by: Yannis Gerlach <100762533+ygerlach@users.noreply.github.com> --- src/Core/Main.vala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Core/Main.vala b/src/Core/Main.vala index e3b2e6e..25a9eb5 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -3045,9 +3045,8 @@ public class Main : GLib.Object{ // Perform any post-restore actions log_debug("Running post-restore tasks..."); - string sh = "if [ -d \"/etc/timeshift/restore-hooks.d\" ]; then \n"; - sh += " run-parts --verbose /etc/timeshift/restore-hooks.d \n"; - sh += "fi \n"; + string sh = "test -d \"/etc/timeshift/restore-hooks.d\" &&" + " run-parts --verbose /etc/timeshift/restore-hooks.d"; exec_script_sync(sh, null, null, false, false, false, true); log_debug("Finished running post-restore tasks..."); From af58af3dff20ff7baaf057d86ce5ecd0321774fa Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Mon, 6 Jan 2025 10:43:12 +0100 Subject: [PATCH 06/10] #365 indicate debianutils/run-parts dependency --- debian/control | 2 +- src/Core/Main.vala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/control b/debian/control index 89e773f..0215d47 100644 --- a/debian/control +++ b/debian/control @@ -18,7 +18,7 @@ Homepage: https://github.com/linuxmint/timeshift Package: timeshift Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, rsync, btrfs-progs | btrfs-tools +Depends: ${shlibs:Depends}, ${misc:Depends}, rsync, debianutils, btrfs-progs | btrfs-tools Replaces: timeshift-btrfs Description: System restore utility Timeshift is a system restore utility which takes snapshots diff --git a/src/Core/Main.vala b/src/Core/Main.vala index 25a9eb5..37d3174 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -352,7 +352,7 @@ public class Main : GLib.Object{ log_debug("Main: check_dependencies()"); - string[] dependencies = { "rsync","/sbin/blkid","df","mount","umount","fuser","crontab","cp","rm","touch","ln","sync","which"}; //"shutdown","chroot", + string[] dependencies = { "rsync","/sbin/blkid","df","mount","umount","fuser","crontab","cp","rm","touch","ln","sync","which", "run-parts"}; //"shutdown","chroot", string path; foreach(string cmd_tool in dependencies){ From 4dac0e2dda628b509e7017cfc9503e8cede7d006 Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:08:13 +0100 Subject: [PATCH 07/10] #365 fix compilation issue after refactor scripts --- src/Core/Main.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/Main.vala b/src/Core/Main.vala index 37d3174..53eec92 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -1696,7 +1696,7 @@ public class Main : GLib.Object{ // Perform any post-backup actions log_debug("Running post-backup tasks..."); - string sh = "test -d \"/etc/timeshift/backup-hooks.d\" &&" + string sh = "test -d \"/etc/timeshift/backup-hooks.d\" &&" + " run-parts --verbose /etc/timeshift/backup-hooks.d"; exec_script_sync(sh, null, null, false, false, false, true); @@ -3045,7 +3045,7 @@ public class Main : GLib.Object{ // Perform any post-restore actions log_debug("Running post-restore tasks..."); - string sh = "test -d \"/etc/timeshift/restore-hooks.d\" &&" + string sh = "test -d \"/etc/timeshift/restore-hooks.d\" &&" + " run-parts --verbose /etc/timeshift/restore-hooks.d"; exec_script_sync(sh, null, null, false, false, false, true); From 20dc01ccdd62780c4b9298eaa54533bd01deb233 Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Mon, 6 Jan 2025 21:55:31 +0100 Subject: [PATCH 08/10] #365 export TS_SNAPSHOT_PATH for use in restore hook --- src/Core/Main.vala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Core/Main.vala b/src/Core/Main.vala index 53eec92..e9e08ae 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -3046,9 +3046,11 @@ public class Main : GLib.Object{ log_debug("Running post-restore tasks..."); string sh = "test -d \"/etc/timeshift/restore-hooks.d\" &&" + - " run-parts --verbose /etc/timeshift/restore-hooks.d"; + " export TS_SNAPSHOT_PATH=\"" + snapshot_to_restore.path + "\" &&" + + " run-parts --verbose /etc/timeshift/restore-hooks.d"; exec_script_sync(sh, null, null, false, false, false, true); + log_debug("Finished running post-restore tasks..."); if (restore_current_system){ From 7aa8bdf2c923c514193443e361b5b64687230ef7 Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Mon, 6 Jan 2025 22:02:10 +0100 Subject: [PATCH 09/10] #365 export TS_SNAPSHOT_PATH for use in backup hook --- src/Core/Main.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Core/Main.vala b/src/Core/Main.vala index e9e08ae..f25d5a2 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -1697,7 +1697,8 @@ public class Main : GLib.Object{ log_debug("Running post-backup tasks..."); string sh = "test -d \"/etc/timeshift/backup-hooks.d\" &&" + - " run-parts --verbose /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..."); From f7a4c88aefe44003ddfa2087ccd287d4742ae644 Mon Sep 17 00:00:00 2001 From: mwoz123 <4487025+mwoz123@users.noreply.github.com> Date: Mon, 6 Jan 2025 22:05:34 +0100 Subject: [PATCH 10/10] #365 update readme for TS_SNAPSHOT_PATH --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be5bbfd..d2b7043 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ You can selectively include items for backup from the ***Settings*** window. Sel - **@** and **@home** subvolumes may be on same or different BTRFS volumes - **@** may be on BTRFS volume and **/home** may be mounted on non-BTRFS partition - If swap files are used they should not be located in **@** or **@home** and could instead be stored in their own subvolume, eg **@swap** - - Separate partitions (e.g. `/boot`) can be handled via custom created hooks (placed in `/etc/timeshift/backup-hooks.d/` and `/etc/timeshift/restore-hooks.d/`) + - Separate partitions (e.g. `/boot`) can be handled via custom created hooks (placed in `/etc/timeshift/backup-hooks.d/` and `/etc/timeshift/restore-hooks.d/`). Script naming must match `run-parts` [requirements](https://manpages.ubuntu.com/manpages/noble/man8/run-parts.8.html). Current snapshot path is exported as `TS_SNAPSHOT_PATH`. - Other layouts are not supported - Make sure, that you have selected subvolume *@* or */@* for root. You can check that executing script below, and if output is *OK*, then everything is alright.