Skip to content

Create: Report an error when the BTRFS snapshot fails - #600

Open
wmutschl wants to merge 1 commit into
linuxmint:masterfrom
wmutschl:fix-create-exit-code
Open

wmutschl wants to merge 1 commit into
linuxmint:masterfrom
wmutschl:fix-create-exit-code

Conversation

@wmutschl

@wmutschl wmutschl commented Nov 27, 2026 •

Copy link
Copy Markdown

Create: Report an error when the snapshot fails

timeshift --create and the scheduled timeshift --check exit with status 0 when the snapshot fails. create_snapshot_for_tags() logs "Failed to create snapshot" but still returns true when create_snapshot_with_btrfs() or create_snapshot_with_rsync() returns no snapshot, and the window says "Snapshot Created".

To reproduce on BTRFS, activate a swap file in the root subvolume (btrfs refuses to snapshot it):

sudo timeshift --create --comments test; echo $?
...
E: ERROR: cannot snapshot '/run/timeshift/.../@': source subvolume contains an active swapfile (Text file busy)
Failed to create snapshot
0

This PR returns false in that case, like the other error paths of the function: --create exits with 1, --check logs "Daily snapshot failed!" and exits with 1, and the window shows "Snapshot Created With Errors" (it still closes after a second; the desktop notification "Failed to create snapshot" stays).

Because create_snapshot() now returns before repo.auto_remove(), which used to delete the empty directory of the failed attempt as an invalid snapshot, the directory is deleted right away when btrfs fails. Otherwise every failed scheduled run would leave an empty directory in timeshift-btrfs/snapshots.

Scripts that run timeshift --create before a package operation and stop when it fails (e.g. timeshift-autosnap-apt) now stop the package operation when the snapshot fails; until now they always continued.

Tested in a Linux Mint 22.3 VM (BTRFS): exit status 1 after failed on-demand and scheduled snapshots, 0 after successful ones, no leftover directories.

create_snapshot_for_tags() logged "Failed to create snapshot" when
create_snapshot_with_btrfs() or create_snapshot_with_rsync() returned
no snapshot, but still returned true. So `timeshift --create` and the
scheduled `timeshift --check` exited with status 0 although no snapshot
was created (for example when btrfs refuses to snapshot a subvolume
with an active swap file), and the window said "Snapshot Created"
instead of "Snapshot Created With Errors".

Return false in this case, like the other error paths of the function.

create_snapshot() now returns before repo.auto_remove(), which used to
delete the empty snapshot directory of the failed attempt as an invalid
snapshot. So delete it right away when btrfs fails, otherwise every
failed scheduled run would leave an empty directory behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wmutschl wmutschl changed the title Create: Report an error when the snapshot fails Create: Report an error when the BTRFS snapshot fails Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant