I’m encountering an issue while creating backups with Restic and would appreciate some assistance.
Here’s my situation: I have data in a specific folder on my disk that can change and even be completely deleted (unmounted) by users. I need to back up this data roughly once a day. It is crucial that the files do not change or get deleted during the backup process.
To handle this, I decided to copy the files to a temporary folder and create the backup from there. When copying the files, I use the cp -rp command to preserve all attributes and permissions. However, when I create the backup with Restic, even though I specify the correct parent snapshot ID, it still thinks that all the directories have changed, even though they haven’t.
Here’s my process:
Copying files from the source folder to the temporary folder: cp -rp /source_directory/* /temporary_directory/
Creating the backup from the temporary folder using Rustic and specifying the parent snapshot ID. sudo restic -r /mnt/user-data/777/u-7777 --password-file /root/.restic_password_file.txt backup --host worker --parent 9c12c1d9 --ignore-inode .
As a result, Rustic considers all directories to be modified, leading to unnecessary full scan, which is inefficient.
repository b9e19c33 opened successfully, password is correct
using parent snapshot 9c12c1d9
Files: 0 new, 3 changed, 117948 unmodified
Dirs: 0 new, 27983 changed, 0 unmodified
Added to the repo: 51.186 MiB
processed 117951 files, 2.758 GiB in 0:04
snapshot e322d117 saved
Can you please advise what I might be doing wrong or suggest any additional options I can use to avoid this issue?
Then you need to use the snapshot feature of for example BTRFS or LVM and backup that instead of backing up a copy. Or use rsync to keep a single copy up-to-date each day instead of a new copy every day. Read on…
That is because all files and directories have new inode numbers, because you are making a new copy each day.
Just asking: is it worth doing the temporary copy? Couldn’t it be that the files are in an inconsistent state during the copy just as during the restic backup? I would guess that copying the files takes longer than restic and has more chances to read opened files. But I could be mistaken.
I’ll agree with what others have already said; snapshots of the backup target are (IMO) the best solution to ensuring all the files are in a “consistent” state during the backup.
Something that stood out to me in particular though:
can change and even be completely deleted (unmounted) by users
If the target directory being unmounted is a particular issue, you might want to consider making the restic job dependant on the target directory in question being a mount point.
If you’re triggering the restic backup via a systemd service, that’s fairly straightforward, see the “ConditionPathIsMountPoint=” systemd unit condition (documentation link).
I attempted to clone a volume and use it as a backup source, but unfortunately, the outcome remained the same - all directories are marked as modified. Here’s what I did: