linuxmint / timeshift

System restore tool for Linux. Creates filesystem snapshots using rsync+hardlinks, or BTRFS snapshots. Supports scheduled snapshots, multiple backup levels, and exclude filters. Snapshots can be restored while system is running or from Live CD/USB.
2.53k stars 91 forks source link

No snaps on restore #179

Open antonio-petricca opened 1 year ago

antonio-petricca commented 1 year ago

Describe the bug

I backed up my system and restored on a new disk (with same partitions of the same size).

After this on the restored one the /snap mount point is empty and so snap applications do not start.

System:

bandisast commented 1 year ago

Check out this issue

antonio-petricca commented 1 year ago

Unfortunately it is not the same issue.

Here is my configuration:

image

bandisast commented 1 year ago

Does anything exist in the /var/lib/snapd/ directory?

antonio-petricca commented 1 year ago

Here is the exact issue https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1900326 .

antonio-petricca commented 1 year ago

Does anything exist in the /var/lib/snapd/ directory?

Sure!

image

antonio-petricca commented 1 year ago

I think that this issue should be investigated.

At the moment Timeshift cannot restore a fully working OS backup. :(

antonio-petricca commented 1 year ago

I posted the question at https://forum.snapcraft.io/t/timeshift-fails-restoring-snapshots/34857 .

antonio-petricca commented 1 year ago

Hi @bandisast @mtwebster @tpraxl any idea about this issue?

I think that it should be impossible that any other user observed the same blocking issue.

Regards, Antonio

nikosdion commented 1 year ago

Why am I even being at-mentioned here…? I have nothing to do with this repository.

shmu26 commented 1 year ago

I can confirm that restore jobs consistently result in corrupted snaps. Please fix.

Obscerno commented 1 year ago

I also have this issue. Details about this that hopefully help:

I'll update again when I have more details, hopefully tomorrow.

Obscerno commented 1 year ago

Okay yes, so the /snap folder does have most of the needed files, but there is no /snap/bin/ directory and all of the current symlinks are missing.

But there were also other little things wrong, to the point where I think my best current workaround is to:

This is straightforward and doesn't require access to the original drive.

antonio-petricca commented 1 year ago

Thank you @Obscerno , unfortunately this is only a workaround. The issue should be addressed in Timeshift directly.

I don't know why the Ubuntu and the Linuxmint teams ship this tool as stock tool if it does not work as expected!

Obscerno commented 1 year ago

Oh yes @antonio-petricca I agree it would be nice to see it fixed, but in the meantime hopefully it will help other poor saps that end up here like I did haha.

MikeNavy commented 9 months ago

Hi,

Googling for topics related to Timeshift and snaps restore, I have found this old closed issue on Timeshift GitHub, at the time it was developed by Tony George: https://github.com/teejee2008/timeshift/issues/701. In the discussion, Tony George says:

/snap is a read-only mount. Actual snap files are kept in the /var/lib/snapd/ directory. it is excluded on purpose. Closing this issue.

About snaps directories: "/snap": virtual directories, read-only, containing snaps mounted while running; should not be backed up by Timeshift. "/snap/bin": contains environment wrappers for the installed snaps, or, in recent versions, symlinks to "/usr/bin/snap" where are found the wrappers; should be backed up and restored by Timeshift, since these wrappers or symlinks are created when a snap is installed. "/usr/bin/snap": should be backed up and restored by Timeshift. "/var/snap/": data and configuration files of running snaps; should not be backed up. "/var/lib/snapd": contains the installed snaps; should be backed up and restored by Timeshift. "~/snap": contains the snaps configurations, on user home; should be backed up and restored by a data backup program (like FreeFileSync), though Timeshift could do it.

So, comparing this with the old closed issue, it appears that Timeshift doesn't backup "/snap" directory at all, while it should at least backup the "/snap/bin" subdirectory.

This is probably the cause to Timeshift not able to correctly back up and restore snaps.

To fix it seems easy for a Timeshift maintainer.

Regards,

MN

MikeNavy commented 9 months ago

Hi,

I confirm the preceding analysis. Here is the list of excluded directories, from Timeshift sources, https://github.com/linuxmint/timeshift/blob/master/src/Core/Main.vala

exclude_list_default.add("/dev/"); exclude_list_default.add("/proc/"); exclude_list_default.add("/sys/"); exclude_list_default.add("/media/"); exclude_list_default.add("/mnt/"); exclude_list_default.add("/tmp/"); exclude_list_default.add("/run/"); exclude_list_default.add("/var/run/"); exclude_list_default.add("/var/lock/"); //exclude_list_default.add("/var/spool/"); exclude_list_default.add("/var/lib/dhcpcd/"); exclude_list_default.add("/var/lib/docker/"); exclude_list_default.add("/var/lib/schroot/"); exclude_list_default.add("/lost+found"); exclude_list_default.add("/timeshift/"); exclude_list_default.add("/timeshift-btrfs/"); exclude_list_default.add("/data/"); exclude_list_default.add("/DATA/"); exclude_list_default.add("/cdrom/"); exclude_list_default.add("/sdcard/"); exclude_list_default.add("/system/"); exclude_list_default.add("/etc/timeshift.json"); exclude_list_default.add("/var/log/timeshift/"); exclude_list_default.add("/var/log/timeshift-btrfs/"); exclude_list_default.add("/swapfile"); exclude_list_default.add("/snap/*");

Since"/snap" is excluded, "/snap/bin" is not backed up, and when Timeshift is restored, the content of "/snap/bin" is considered as files having changed since the last snapshot and are deleted.

Regards,

MN

antonio-petricca commented 9 months ago

Good diagnose! Could ypu provide a PR?

MikeNavy commented 9 months ago

Hi

I am not a developer and not involved in Timeshift development.

I have just performed an analysis concluding to a potential bug cause.

It is now to Timeshift maintainers to go further, confirm or not my analysis, change the code and fix the bug, and release a new version for test.

Regards,

MN

Le 28 févr. 2024 à 13:29, Antonio Petricca @.***> a écrit :

 Good diagnose! Could ypu provide a PR?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

antonio-petricca commented 9 months ago

No problem :).

I am a developer, so I could try to find some time to validate your analysis on a virtual machine, and if it will work I could issue a pull request!

Il Mer 28 Feb 2024, 13:38 MikeNavy @.***> ha scritto:

Hi

I am not a developer and not involved in Timeshift development.

I have just performed an analysis concluding to a potential bug cause.

It is now to Timeshift maintainers to go further, confirm or not my analysis, change the code and fix the bug, and release a new version for test.

Regards,

MN

Le 28 févr. 2024 à 13:29, Antonio Petricca @.***> a écrit :

 Good diagnose! Could ypu provide a PR?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

— Reply to this email directly, view it on GitHub https://github.com/linuxmint/timeshift/issues/179#issuecomment-1968898128, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABS2CIVJ5IPENN3VJWZG7WDYV4QMXAVCNFSM6AAAAAAXD6BAT2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRYHA4TQMJSHA . You are receiving this because you were mentioned.Message ID: @.***>

MikeNavy commented 9 months ago

Hi,

You should read this post: https://forums.linuxmint.com/viewtopic.php?t=414183

In the latest two messages a problem is mentioned: /timeshift appears in the exclude list while timeshift snapshots, when on system disk, are not empty after a restore.

So, there may be different kinds of exclude lists (backup / restore) or somewhere specific instructions concerning Timeshift.

In another ".vala" source file, there are files excluded based on their suffix, like ".old".

So, Timeshift is far to make complete system files snapshots. Tony George made some design choices, and these choices should be checked to see if they are still valid.

Regards,

MN

Le 28 févr. 2024 à 13:42, Antonio Petricca @.***> a écrit :

 No problem :).

I am a developer, so I could try to find some time to validate your analysis on a virtual machine, and if it will work I could issue a pull request!

Il Mer 28 Feb 2024, 13:38 MikeNavy @.***> ha scritto:

Hi

I am not a developer and not involved in Timeshift development.

I have just performed an analysis concluding to a potential bug cause.

It is now to Timeshift maintainers to go further, confirm or not my analysis, change the code and fix the bug, and release a new version for test.

Regards,

MN

Le 28 févr. 2024 à 13:29, Antonio Petricca @.***> a écrit :

 Good diagnose! Could ypu provide a PR?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

— Reply to this email directly, view it on GitHub https://github.com/linuxmint/timeshift/issues/179#issuecomment-1968898128, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABS2CIVJ5IPENN3VJWZG7WDYV4QMXAVCNFSM6AAAAAAXD6BAT2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRYHA4TQMJSHA . You are receiving this because you were mentioned.Message ID: @.***>

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

antonio-petricca commented 9 months ago

I forked the project, made some changes to the code and tested it on a virtual machine.

The only working solution was to fully backup the /snap folder (subfolders symlinks are taken in charge by rsync too).

I snapshotted the VM adding and removing snap applications, then restoring them by different backups, and it worked.

I kindly ask to anybody to test it in order to issue a valid PR to the maintainer.

Here are the compiled binaries: https://github.com/antonio-petricca/timeshift_snap_fix/releases/download/snap-fix-1/timeshift.zip .

Regards, Antonio

MikeNavy commented 9 months ago

Hi,

Some comments about the test: since most users use Timeshift scheduling (what I don't use), they could have some running snaps when Timeshift snapshot is done. Did you test your fixed version with at least a running snap when the snapshot is saved? And, in that case, what does it occur when restoring the snapshot (without running snap / with the same snap running)?

Tony George probably had a good reason to not back up /snap (but he was wrong to not back up /snap/ bin). I have been surprised to see that /timeshift is in the list of excluded directories; this directory is used to save snapshots when they are saved on the computer disk; and the snapshots are not deleted after restore... So, there is somewhere in the code à special "treatment" of /timeshift directory, and it might be applied to /snap/bin.

Another possibility would be to fully backup /snap content, but to restore only /snap/bin.

I have not yet installed any snap. I was thinking to use snaps instead of flatpaks since recent runtimes have changed the way to call video and my Nvidia GPU, as any using 390.157 drivers, no longer works. I will try to install a snap and try your version.

Regards,

MN

Le 29 févr. 2024 à 10:00, Antonio Petricca @.***> a écrit :

 I forked the project, made some changes to the code and tested it on a virtual machine.

The only working solution was to fully backup the /snap folder (subfolders symlinks are taken in charge by rsync too).

I snapshotted the VM adding and removing snap applications, then restoring them by different backups, and it worked.

I kindly ask to anybody to test it in order to issue a valid PR to the maintainer.

Here is the compiled binaries: https://github.com/antonio-petricca/timeshift_snap_fix/releases/download/snap-fix-1/timeshift.zip .

Regards, Antonio

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

antonio-petricca commented 9 months ago

I think that avoiding to backup the /snap/ folders produces a not working restore. In such situation the restore recreates the configuration folders, but you should force a manuall reinstall of each snap application.

I think also that Timeshift cannot have to deal with the fact that some snap application are running or not, else, which would be the alternative? Apart from that I did not test the scenario you described. Could you kindly do that?

I tried to backup only the /snap/bin/ folders (look at the following code, that I commented out to keep it disabled, but available for future improvements), but the restore process does not recreate the symlinks under each /snap subfolder, which results in unusable snap applications:

log_debug("Main: excluding/filtering '/snap/subfolders/' ...");

var snapBaseFolder = "/snap";
var snapSubfolders = dir_list_names(snapBaseFolder);

foreach(var snapSubfolder in snapSubfolders) {
    if (snapSubfolder == "bin") {
        log_debug(@"Main: folder '$snapBaseFolder/$snapSubfolder' held.");
    } else {
        exclude_list_default.add(@"$snapBaseFolder/$snapSubfolder");
        log_debug(@"Main: folder '$snapBaseFolder/$snapSubfolder' excluded.");
    }
}

For all the above reasons I simply removed the /snap/ exclusion, and in all my tests it worked.

Could you kindly test the running apps scenario and report here your results?

Regards, A.

MikeNavy commented 9 months ago

Test of modified Timeshift.

My operating system: Linux Mint 21.3 Mate, based on Ubuntu Jammy 22.04 LTS

0) I have backed up my system with a Timeshift snapshot, and my home with FreeFileSync.

1) I have downloaded the zip file, extracted its content, moved the directory in my home, "~/opt/timeshift".

2) Test timeshift-gtk launch: in a terminal open in "~/opt/timeshift", tried "./timeshift-gtk"; error message: to copy system files you need to run the command with sudo (Timeshift polkit is not recognized); second test "sudo -H ./timeshift-gtk", and the application is launched.

3) Snap installation:

4) Gedit test:

5) Modified Timeshift test:

6) Timeshift restore test:

(timeshift-gtk:4659): Gdk-ERROR **: 12:21:22.244: The program 'timeshift-gtk' received an X Window System error. This probably reflects a bug in the program. The error was 'BadDrawable (invalid Pixmap or Window parameter)'. (Details: serial 78947 error_code 9 request_code 139 (RENDER) minor_code 4) (Note to programmers: normally, X errors are reported asynchronously; that is, you will receive the error a while after causing it. To debug your program, run it with the GDK_SYNCHRONIZE environment variable to change this behavior. You can then get a meaningful backtrace from your debugger if you break on the gdk_x_error() function.) Trappe pour point d'arrêt et de trace

End of the test.

Timeshift snapshot creation did work, Timeshift snapshot restore failed.

Regards,

MN

antonio-petricca commented 9 months ago

Please let me some time to carefully read your post. At the moment I have my PC in my hands...

antonio-petricca commented 9 months ago

Hi, I read carefully your post.

I don't think the issue you got comes from my timeshift patch.

By the way I will try the same on my VM. If it will work I will send the PR.

I will inform you about my test...

Thank you very much for your contribution, A.

antonio-petricca commented 9 months ago

I just tried a bit more complex scenario (gedit running, firefox playing some videos, ...) and I got no issues, and I got a fully working environment.

For the above reason I am going to send my PR.

antonio-petricca commented 9 months ago

The PR is https://github.com/linuxmint/timeshift/pull/279 .