Avoiding file deletion changes when backing up phone memory

Hello!
I’d like to use restic to create backups of my Android phone’s flash memory.
I have access to the phone storage via MTP.

My idea was to copy everything relevant from the phone to my PC’s hard disk in a “work directory”, and then create the repo and snapshots based on the work directory onto an external HDD.

However, this approach brings in a problem.
I want to do selective incremental backups, as in, let’s say I took a bunch of new photos and want to back only those up. I’d like to create a snapshot that only contains the new photos and nothing else.

But in order to achieve these “pure addition” snapshots, I’m forced to either always restore the entire phone memory into my work directory from previous snapshots, or to always keep a mirror of my phone’s flash memory on my PC’s disk. Neither of these options is really desirable; I don’t want eat up a sizeable portion of my PC’s storage space with a full copy of my phone’s flash memory, nor do I want to accelerate my hard drive’s inevitable death by unleashing this many (mostly unnecessary) I/O operations on it just to make partial backups of my phone memory (and to delete everything again).

If I only have the new photos I want to back up in the work directory and create a snapshot from those, restic will mark my old unchanged files as “deleted”. This I would like to avoid as well.

Is there a way to achieve this without having to do full restores or keeping a mirror on disk? Or maybe having the old files marked as deleted isn’t that big of a deal? I’m afraid it’d bite me in the butt when I’d like to do a restore, but I’m not that well-versed with restic to be fully aware of the implications.

Thanks!

I think the only solution that avoids keeping a mirror of the phone data on your PC, is to run restic with direct access to the phone storage.
A cursory google search for “mtp mount” shows that there are third party solutions to make MTP devices accessible via regular file paths, which restic should then be able to access normally.
Alternatively, I believe restic could be installed and run directly from the android phone itself, which would give it direct storage access.

To get your “pure addition” snapshots, you would then have to pass restic the list of files/folders to backup.

The above said, there seems to be a misconception here:

If I only have the new photos I want to back up in the work directory and create a snapshot from those, restic will mark my old unchanged files as “deleted”. This I would like to avoid as well.

Backing up new files/folders has no impact on your older snapshots. They still exist and can be restored from, and if the files were included again in a future backup, they would be deduplicated against the older snapshots. The only time snapshots get removed is when you run restic forget.

Something you may want to consider though is if you’re only backing up new files in each new snapshot, when it comes time to restore, you’re going to have to locate the specific snapshot that contains the files you want before you can perform the restore. Also, if you wanted to restore everything (say to a new phone), you would need to do n restore operations, with n being the number of snapshots you have.

If you’ll permit a little unsolicited advice, I’d personally question the value of making “pure addition” snapshots. They’re going to be effectively no smaller than just taking snapshots of the entire directory (or directories) of interest, due to restic’s deduplication, and they will make future restore operations more complex. But, if your use case requires that each snapshot only contain the new files since the last snapshot, then carry on :slight_smile:

There’s currently no command that allows creating a new snapshot as a combination of an existing snapshot and new files. I think there’s a pull request that wants to add that feature, but it will at least take quite some time until I get around to take a look at that.

Thank you for the inputs!
Yeah, the reason I’m trying to steer towards the “pure addition” snapshots is to avoid having to have a mirror of the phone’s memory either temporarily or permanently on my PC. If I can avoid that, I’m good with non-pure-addition snapshots.
For now I’ll try to mount the MTP device as a drive but I feel like it’s going to be a bumpy road.

Running restic from the phone doesn’t actually sound that bad, but it does sound a bit unwieldy, especially if I want to add custom flags to restic. Also I’ve already made my first full snapshot of the phone memory using a temporary mirror on my PC, so having to delete that to start from scratch would only add to the inconveniences.

Running restic from the phone doesn’t actually sound that bad, but it does sound a bit unwieldy, especially if I want to add custom flags to restic.

Yeah, some amount of scripting would be useful if running restic using tmux or similar, and I’m not sure how to solve the problem of scheduling.
This forum thread might start you on the right path, there’s an android app linked towards the bottom of the discussion that looks like it might work for your use case, although I’ve not used it myself (I personally use the Syncthing approach mentioned in that thread).

Also I’ve already made my first full snapshot of the phone memory using a temporary mirror on my PC, so having to delete that to start from scratch would only add to the inconveniences.

No need to delete it. The source data is the same, so while restic will have to re-scan everything during your first backup run against the new path to the data (either mounted MTP, or otherwise), it will identify the data all exists in the repository already, so only write some new metadata. You can delete the old snapshot for neatness once done, or just leave it be.