Skip to content

Publish the progress of a running task, and count it against the latest snapshot - #595

Open
martin152 wants to merge 1 commit into
linuxmint:masterfrom
martin152:publish-progress
Open

martin152 wants to merge 1 commit into
linuxmint:masterfrom
martin152:publish-progress

Conversation

@martin152

Copy link
Copy Markdown

During a scheduled snapshot nothing outside the process knows how far it has got. The percentage
is printed to stdout, which cron throws away, and the window refuses to open while it runs.

With this change the running instance writes a small JSON file next to the lock,
/var/run/lock/timeshift/status, about once a second while it creates, deletes or restores a
snapshot or checks the free space. It holds the pid, the lock mode, what it's doing, the snapshot
name, progress, seconds_remaining and the counts, i.e. the same numbers the window shows. Anyone
can read it, it's written through a rename so a reader never gets half a file, and it goes away
with the lock. It lives outside the backup mount on purpose. When I followed a run by reading
rsync-log inside /run/timeshift/<pid>/backup, the open file kept the mount busy and Timeshift
failed to unmount it at the end ("E: Failed to unmount").

The same commit also fixes the total those numbers are based on. Copies counted against
snapshot_count from timeshift.json, which is saved once during setup. Mine says 1,612,943 while
my snapshots now have about 1,968,000 entries, so the bar would end near 122 % (#461 looks like
the same thing). Copies now count against the snapshot they link from, deletes against the
snapshot being deleted, like restores already do. The saved figure is still used when there's no
snapshot yet.

On a scratch disk image with 40,220 entries and snapshot_count left at 1000, the last progress
line of a second snapshot was 4022.00% complete on master and 100.00% complete with this
branch. The status file during that run looked like this:

{"pid":2537954,"mode":"ondemand","action":"creating","snapshot":"2026-11-24_00-23-04",
 "progress":0.9308,"seconds_remaining":0,"count":37439,"count_total":40220,"updated":1795476186}

One thing I didn't solve here. An incomplete snapshot has no file_count, so deleting one still
falls back to the saved figure.

I also ran it for one real snapshot of my system (1.97 million entries, 12 minutes). The status
file was rewritten every second the whole time, and the bar moved like this:

00:37:06  10.1 %   712 s left
00:41:08  38.0 %   524 s left
00:43:48  72.9 %   179 s left
00:47:37 100.1 %     0 s left

It ends a little over 100 % (100.21 % on stdout), because the system had about 2,600 more
entries than the snapshot it linked from. That seems fine to me.

Two other pull requests build on this file: one for the window (opening it while a scheduled
snapshot runs) and one for the panel hint in mintreport.

…snapshot

While a snapshot is created, checked for space, deleted or restored,
the running instance now writes what it is doing to
/var/run/lock/timeshift/status next to the lock: pid, mode, action,
snapshot name, progress, seconds remaining and the counts. The file is
readable by every user and is removed with the lock, so a panel applet
or a second window can show the same progress the window shows today.
A scheduled run's progress was only printed to a stdout nobody reads.

The total for that progress was the file count saved when Timeshift
was set up (Main.first_snapshot_count). On a system that has grown
since, the bar passes 100 % long before the end (linuxmint#461). Copies now
count against the snapshot they link from, and deletes against the
snapshot being deleted, as restores already did; the saved figure is
only used when there is no snapshot yet.
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