1

I am trying to backup a failing hard drive and rsync would be ideal due to the features it has such as progress indicator and ability to stop and resume. The one issue I am having is that while file date modified attribute is preserved the directories get new date attribute. This causes issues as I sort many files by date so I know what was added more recently. Is it possible to preserve directory date modified attribute with rsync:

sudo rsync -avhX --progress --info=progress2 /mnt/failing/ /mnt/new/

-t (included with -a) option preserves the file attributes but does not mention directories. Is there any special requirement for ownership / permissions of the /mnt/new partition to preserve certain attributes successfully?

2

The last modification time of directories is preserved by -a, but you can only see this when rsync finishes. It does not try to set the time on directories that are constantly being updated with new files.

You can test this yourself. Create a directory and set the date on it to yesterday, then copy it with rsync:

$ mkdir d1 d2
$ ls -ld d1
drwxr-xr-x 2  40 Nov  4 14:41 d1
$ touch -d 'yesterday' d1
$ ls -ld d1
drwxr-xr-x 2  40 Nov  3 14:41 d1
$ rsync -i -avR d1 d2
$ ls -ld d1 d2/d1/
drwxr-xr-x 2  40 Nov  3 14:41 d1
drwxr-xr-x 2  40 Nov  3 14:41 d2/d1/

The d2/d1 dir has yesterday's date. We can override it and see if rsync fixes things:

$ touch d2/d1
$ ls -ld d1 d2/d1/
drwxr-xr-x 2  40 Nov  3 14:41 d1
drwxr-xr-x 2  40 Nov  4 14:42 d2/d1/
$ rsync -i -avR d1 d2
.d..t...... d1/
$ ls -ld d1 d2/d1/
drwxr-xr-x 2  40 Nov  3 14:41 d1
drwxr-xr-x 2  40 Nov  3 14:41 d2/d1/

rsync -i shows the timestamp is wrong on d2/d1 and fixes it.

  • Ahhhhhhh, that's interesting. Does that also apply to permissions and ownership on directories? If so that's another mystery solved :) Will start the rsync job right now, though it will take a day or so since it's an 8tb drive. – DominicM Nov 4 '15 at 14:41
  • I'm not sure in what order things are done, but the end result is usually what I expect. rsync even copies files to/from directories that have no write permissions without problems. Obviously to preserve ownership you need to run as root, as you are doing. By the way, a useful extra option can be -H to preserve hard links, in case you have any files linked together. – meuh Nov 4 '15 at 15:24
  • What happens if rsync is stopped with lets say ctrl+z? I think that was why it did not work for me. Is there a way to terminate rsync command gracefully to allow attributes to apply? Perhaps permissions would get applied when entire directory is synced even for files copied with interrupted command before? – DominicM Nov 4 '15 at 15:33
  • I can only suggest you try and see on some subset of your files. My experience is that no matter what state things are left in, a second rsync will quickly go through the hierarchy and put things right. You can get lots of detailed output with option --debug=all4 as well as -i. – meuh Nov 4 '15 at 15:43
0

rsync -avz is doing for me everything
- v is for verbose
- a is for archive mode ( similar to -rlptgoD)
- z is to use compression

0

I ended up doing a write up about this issue in case it is useful to someone. Practically every bit of metadata can be preserved with Rsync as explained in the post.

Replace Storage Drives with Rsync in Arch Linux

Here's a snippet to sync everything:

sudo rsync -avihXP --info=progress2 --stats --dry-run /mnt/disk?/ /mnt/temp/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.