bit-team / backintime

Back In Time - An easy-to-use backup tool for GNU Linux using rsync in the back
https://backintime.readthedocs.io
GNU General Public License v2.0
2.01k stars 197 forks source link

restore doesn't preserve directory mtimes with "backup on restore" option #1007

Open protist opened 5 years ago

protist commented 5 years ago

I just did a restore, and I realised that modification times of directories were not preserved. I checked the rsync command, and I realised that it is because backintime uses the --backup flag when restoring. From man rsync:

-b, --backup ... Note that if you don’t specify --backup-dir, (1) the --omit-dir-times option will be forced on

I'm not sure why that is; it doesn't make sense to me. In any case, my expectation was that backintime would preserve all modification times. Obviously I can see the merit of using --backup in general, but when restoring directories, I'd rather manually rsync -a instead, which is less convenient, but preserves all modification times.

buhtz commented 1 year ago

@protist There is a new forming maintaining team and we do review all issues. Is this problem still relevant for you, can you reproduce it with a newer or the latest release? Did you find a solution?

Tag: Feedback, Bug

Maybe related to #988

protist commented 1 year ago

@buhtzz Yes, I just tried it again and this bug is still present. To replicate

  1. delete/move a directory
  2. backintime restore <directory>
  3. observe directory's modification date is the time of restore (step 2 above), not the original date

I didn't read the full linked issue, but my interpretation of this problem is still as per my original issue. When restoring, backintime uses --backup. e.g. the command it writes to the terminal is:

rsync --recursive --times --devices --specials --hard-links --human-readable --links --acls --xattrs --perms --executability --group --owner --info=progress2 --no-inc-recursive --numeric-ids -R -v --backup --suffix=.backup.20220926 /path/to/backintime/hostname/root/1/20220926-094501-100/backup/./path/to/dir /

As per my original text, the presence of --backup forces --omit-dir-times. If I remove the --backup part from the command above, this preserves modification times as expected.

emtiu commented 1 year ago

I can confirm and have reproduced this bug.

The problem only occurs when the "Backup replaced files on restore" option is set (or, for a particular restpore run, the "Backup local files before overwriting or removing […]" option is activated.) When this option is unset, directory mtimes are preserved/restored as expected.

Possible solutions

extra run of find and touch

Suggested here, a third run to touch/restore directory mtimes could help, like so: find $dir -type d -exec touch --reference="$backupdir/{}" "{}" \;

This is likely the most time-efficient way to do it.

third rsync run

As suggested here, a third rsync run could restore directory mtimes after backup files have been written.

adding --backup-dir $dir to rsync

This would be a big change, and would fundamentally alter the way that restore works. With this option, all saved-instead-of-overridden or saved-instead-of-deleted files would not be stored in-place, but in a separate copy of the restored directory structure under $dir.