rclone: rclone copy --metadata not working for folders

The associated forum post URL from https://forum.rclone.org

What is the problem you are having with rclone?

I did sudo rclone copy --metadata <src> <dest> as root user To validate the dest content, I did the restore using same rclone cmdline interchanging src and dest as root user. While the files get the right attributes (permission level, owner, group), the folder has got root:root and restore date.

What is your rclone version (output from rclone version)

rclone v1.61.1

  • os/version: oracle 7.9 (64 bit)
  • os/kernel: 5.4.17-2136.314.6.2.el7uek.x86_64 (x86_64)
  • os/type: linux
  • os/arch: amd64
  • go/version: go1.19.4
  • go/linking: static
  • go/tags: none

Which OS you are using and how many bits (e.g. Windows 7, 64 bit)

Oracle Linux Server release 7.9

Which cloud storage system are you using? (e.g. Google Drive)

Oracle Cloud Infrastructure

The command you were trying to run (e.g. rclone copy /tmp remote:tmp)

sudo rclone copy --metadata <src> <dest>

A log from the command with the -vv flag (e.g. output from rclone -vv copy /tmp remote:tmp)

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don’t comment if you have no relevant information to add. It’s just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 38 (15 by maintainers)

Commits related to this issue

Most upvoted comments

I’m willing to pledge $100 for full metadata preservation*. Unfortunately I don’t have the clout to get my employer to sponsor it (I don’t think they use rclone). @ncw do you use something like Bountysource?

* by full metadata what I mean is that

user@A ~$ rclone copy important_docs S2:remote_archive
user@B ~$ rclone copy S2:remote_archive important_docs

should have the exact same result as

user@A ~$ rsync -aHAX important_docs B:/home/user/important_docs

where A and B are both linux systems.

I would also accept non-preservation of hardlinks (i.e., rsync without the -H option). But directory mtime and permissions are a must!

This is for my own usage. Unfortunately I’m not a rich man, have zero Golang experience and not much free time. If there is some sort of crowdfunding/bounty setup I’d be willing to chip in up to say $200.

I have made a first pass at making sync preserve the folder modtimes/metadata here:

v1.66.0-beta.7695.b8c0d3318.fix-6685-dir-sync on branch fix-6685-dir-sync

This is an early beta for comments and testing. It is missing a lot of integration tests so may not work properly!

It has some of your commits in @nielash - thank you! - I re-used them for setting directory modtimes. I renamed the method to DirSetModTime which is not as nice as TouchDir but is consistent with the other methods and doesn’t imply directory creation. Note that it also updates some bisync golden tests in b8c0d3318e9a4137dc8991904dbc3b31ce2be56b in a very minor way.

Here are some notes on how it works and what needs to be done. It also describes how to update a backend to support Directory modtimes or to support Metadata on directories.

Notes

A non metdata sync will sync directory modtimes. This is a change from the existing code but I think it will be welcomed by users. The reads directory ModTime and sets them using DirSetModTime if available (or Directory.SetModTime).

A --metadata sync will read directory metadata (including mod times) using Metadata and set them with SetMetadata

Syncs with and without metadata may have an additional pass afterwards to SetModTimes of directories if they change when files are added (the DirModTimeUpdatesOnWrite feature flag).

FIXME directory wrapping these backends needs fixing to proxy to underlying Directory

  • combine
  • crypt
  • union

They all just need to override the path in the Directory so maybe a generic class to do that is needed.

FIXME need to kill off NewDirCopy - in use by crypt and is wrong - need to make Directory wrapper and proxy everything else to the underlying Directory

TODO

  • sync: tests
  • sync: paralellize setDelayedDirModTimes
  • operations: tests
  • don’t set metadata if it is already set
  • don’t set modtime if it is already set
  • fstests: tests for new features
  • docs - should SetDirModTime/MkdirMetadata be in the overview?
  • more backends
  • make sure we wrap methods on fs.Directory (SetModTime, SetMetadata etc) in all the wrapping remotes
  • can make rclone touch work on directories
  • stats! for mkdir/update metadata changes that happens operations?

fstests

  • DirSetModTime
  • MkdirMetadata
  • Directory.Metadata
  • Directory.SetModTime
  • Directory.SetMetadata
  • make sure Directory does not type assert to fs.Object or fs.ObjectInfo
  • check any backend with MkdirMetadata should support setDirModTime
  • Check if a backend advertises WriteDirModtime then it must allow directories to be created with metadata (MkdirMetadata).
  • Check if a backend advertises WriteDirSetModTime then it must allow directories to be created with modtime (MkdirMetadata).
  • go test -v -run TestIntegration/FsCheckWrap should check Directories are wrapped properly

To add directory metadata to a backend

Decide on feature flags

ReadDirMetadata:          true,
WriteDirMetadata:         true,
WriteDirSetModTime:       true,
UserDirMetadata:          true,
DirModTimeUpdatesOnWrite: true/false,

Make List and ListR return specialized directory objects satisfying these interfaces

fs.Directory
fs.SetModTimer
fs.SetMetadataer

Remember assertions.

Implement the optional method MkdirMetadata. This should create a directory with the metadata given. At minimum the backend should interpret the mtime metadata to set the modification time.

It can implement DirSetModTime too but (I think!) rclone will work without it.

SetModTime only

If a backend can only set modtime on directories and doesn’t have directory metadata

ReadDirMetadata:          false,
WriteDirMetadata:         false,
WriteDirSetModTime:       false,
UserDirMetadata:          false,
DirModTimeUpdatesOnWrite: true/false,

This does not need to make List/ListR return specialized directory objects. Instead it should implement a DirSetModTime optional method.

This is a much simpler integration.

The Date Modified for the folders working for rmount+winfsp (Windows) on the S3 compatible object store layer work correctly in this new version?

I performed tests with the version rclone-v1.67.0-beta.7845.71069ed5c and rclone-v1.66.0-beta.7732.f5f86786b.fix-6685-dir-sync for Windows and after the expiration of the cache time, the date of all folders is changed to 31/12/1999 - The date of files is still correct.

Use this command to mount the driver: rclone mount oci:/rclone-lab Z: --config "C:\Users\Administrator.LAB\AppData\Roaming\rclone\rclone.conf" --vfs-cache-mode writes -o FileSecurity="D:P(A;;FRFW;;;WD)" -o FileSecurity="D:P(A;;FRFWFX;;;WD)" -o FileSecurity="D:P(A;;FA;;;WD)"

Source:

C:\Users\Administrator.LAB\Downloads>dir
 Volume in drive C has no label.
 Volume Serial Number is BC7E-DDD1

 Directory of C:\Users\Administrator.LAB\Downloads

04/04/2024  16:06    <DIR>          .
04/04/2024  10:10    <DIR>          ..
04/04/2024  10:12    <DIR>          nssm-2.24
03/04/2024  14:52           351.793 nssm-2.24.zip
04/04/2024  13:57        36.198.912 RaiDrive_2023.9.90_x64.msi
04/04/2024  16:06    <DIR>          rclone-beta-latest-windows-amd64
04/04/2024  16:06        21.091.532 rclone-beta-latest-windows-amd64.zip
04/04/2024  15:23    <DIR>          rclone-v1.66.0-beta.7732.f5f86786b.fix-6685-dir-sync-windows-amd64
04/04/2024  15:23        20.877.552 rclone-v1.66.0-beta.7732.f5f86786b.fix-6685-dir-sync-windows-amd64.zip
04/04/2024  10:12    <DIR>          rclone-v1.66.0-windows-amd64
03/04/2024  10:57        21.071.308 rclone-v1.66.0-windows-amd64.zip
04/04/2024  10:51                 6 Teste.txt
03/04/2024  11:11         2.207.744 winfsp-2.0.23075.msi
               7 File(s)    101.798.847 bytes
               8 Dir(s)  81.526.992.896 bytes free

Destination:

Z:\>dir
 Volume in drive Z is oci rclone-lab
 Volume Serial Number is 6803-5E5D

 Directory of Z:\

04/04/2024  13:57        36.198.912 RaiDrive_2023.9.90_x64.msi
04/04/2024  10:51                 6 Teste.txt
04/04/2024  10:10               282 desktop.ini
31/12/1999  21:00    <DIR>          nssm-2.24
03/04/2024  14:52           351.793 nssm-2.24.zip
31/12/1999  21:00    <DIR>          rclone-beta-latest-windows-amd64
04/04/2024  16:06        21.091.532 rclone-beta-latest-windows-amd64.zip
31/12/1999  21:00    <DIR>          rclone-v1.66.0-beta.7732.f5f86786b.fix-6685-dir-sync-windows-amd64
04/04/2024  15:23        20.877.552 rclone-v1.66.0-beta.7732.f5f86786b.fix-6685-dir-sync-windows-amd64.zip
31/12/1999  21:00    <DIR>          rclone-v1.66.0-windows-amd64
03/04/2024  10:57        21.071.308 rclone-v1.66.0-windows-amd64.zip
03/04/2024  11:11         2.207.744 winfsp-2.0.23075.msi
               8 File(s)    101.799.129 bytes
               6 Dir(s)  1.125.899.906.842.624 bytes free

I used the following timing commands:

C:\Users\Administrator.LAB\Downloads>rclone sync -vPM . z:
2024/04/05 11:26:32 INFO  : nssm-2.24: Updated directory metadata
2024/04/05 11:26:32 INFO  : rclone-beta-latest-windows-amd64: Updated directory metadata
2024/04/05 11:26:32 INFO  : rclone-v1.66.0-beta.7732.f5f86786b.fix-6685-dir-sync-windows-amd64: Updated directory metadata
2024/04/05 11:26:32 INFO  : rclone-v1.66.0-windows-amd64: Updated directory metadata
2024/04/05 11:26:33 INFO  : nssm-2.24/nssm-2.24: Updated directory metadata
2024/04/05 11:26:33 INFO  : rclone-v1.66.0-windows-amd64/rclone-v1.66.0-windows-amd64: Updated directory metadata
2024/04/05 11:26:33 INFO  : rclone-v1.66.0-beta.7732.f5f86786b.fix-6685-dir-sync-windows-amd64/rclone-v1.66.0-beta.7732.f5f86786b.fix-6685-dir-sync-windows-amd64: Updated directory metadata
2024/04/05 11:26:33 INFO  : rclone-beta-latest-windows-amd64/rclone-v1.67.0-beta.7845.71069ed5c-windows-amd64: Updated directory metadata
2024/04/05 11:26:33 INFO  : dir: Copied (new)
2024/04/05 11:26:33 INFO  : nssm-2.24/nssm-2.24/src: Updated directory metadata
2024/04/05 11:26:33 INFO  : nssm-2.24/nssm-2.24/win32: Updated directory metadata
2024/04/05 11:26:33 INFO  : nssm-2.24/nssm-2.24/win64: Updated directory metadata
Transferred:              0 B / 0 B, -, 0 B/s, ETA -
Checks:                58 / 58, 100%
Transferred:            1 / 1, 100%
Elapsed time:         4.6s
2024/04/05 11:26:35 INFO  :
Transferred:              0 B / 0 B, -, 0 B/s, ETA -
Checks:                58 / 58, 100%
Transferred:            1 / 1, 100%
Elapsed time:         4.6s

Then, the time of the folders is updated correctly, but after the cache time expires, they return to 31/12/1999. Same erro with:

# rclone bisync . Z: --create-empty-src-dirs --compare size,modtime,checksum --slow-hash-sync-only --resilient -MvP --fix-case --resync # rclone sync -vP --metadata-mapper --metadata --refresh-times . Z:

Any news on this?

I’m currently thinking about metadata for directories.

I had a quick thought about this. Would it be of interest if I could write a small command that copies dir modtimes from one remote to another (for backends that support it)? It would be intended as more of a short-term stop-gap to tide us over while we wait hopefully for full dir metadata support, which would be a much more complicated project.

Many backends (including local and drive) already support listing directory modtime, like:

rclone lsf --dirs-only -R --format "pt" src_remote:path

So the command I’m imagining would do basically the equivalent of the above command, then loop through all the results and do something like err = dir.SetModTime(ctx, t) for each corresponding dir on the dest. (Probably with a --modify-window check first, and maybe also support for --update.)

The problem with this idea is that directories don’t support SetModTime at the moment. This is something which will need to be added to backends to support it.

An alternate approach might be to tack it on to the end of copy/sync as an optional extra step, very much like --create-empty-src-dirs.

That is my ultimate plan 😃

My use case is that my Google Drive currently has all the correct modtimes of my folders, and when I use rclone to sync them to a new computer, I want to be able to follow that with a command to copy over all the folder modtimes from drive to local. Modtime is the main piece of dir metadata I care about (especially because of macOS “packages” which are really dirs), so in my opinion, a command like this would deliver a lot of value for relatively little effort.

Is this something you’d want?

It is a very useful thing. However it is not at all a straight forward bit of work since the assumption that rclone can create and destroy directories whenever it wants is baked into every backend.

Some backends will need the modtime of directories updating if you write files in them, but I imagine some won’t.

I had a quick thought about this. Would it be of interest if I could write a small command that copies dir modtimes from one remote to another (for backends that support it)? It would be intended as more of a short-term stop-gap to tide us over while we wait hopefully for full dir metadata support, which would be a much more complicated project.

Many backends (including local and drive) already support listing directory modtime, like:

rclone lsf --dirs-only -R --format "pt" src_remote:path

So the command I’m imagining would do basically the equivalent of the above command, then loop through all the results and do something like err = dir.SetModTime(ctx, t) for each corresponding dir on the dest. (Probably with a --modify-window check first, and maybe also support for --update.)

An alternate approach might be to tack it on to the end of copy/sync as an optional extra step, very much like --create-empty-src-dirs.

My use case is that my Google Drive currently has all the correct modtimes of my folders, and when I use rclone to sync them to a new computer, I want to be able to follow that with a command to copy over all the folder modtimes from drive to local. Modtime is the main piece of dir metadata I care about (especially because of macOS “packages” which are really dirs), so in my opinion, a command like this would deliver a lot of value for relatively little effort.

Is this something you’d want?

@danieldemoraisgurgel

A Data de modificação para as pastas que trabalham para rmount+winfsp (Windows) na camada de armazenamento de objetos compatível com o S3 funciona corretamente nesta nova versão?

Se vocĂȘ adicionar Ă  sua configuraçãodirectory_markers = true

  --s3-directory-markers   Upload an empty object with a trailing slash when a new directory is created

Em seguida, os diretĂłrios terĂŁo uma data persistente - caso contrĂĄrio, eles nĂŁo existem de fato.

Eu nĂŁo acho que a sincronização de tempos de modificação de diretĂłrio ou metadados vai funcionar com ainda. Se vocĂȘ quiser ver isso, abra uma nova edição sobre isso. Se vocĂȘ estĂĄ trabalhando em nome de uma empresa, vocĂȘ pode estar interessado em contratar um contrato de suporte e podemos adicionar isso como parte dele.directory_markers

Yes, we are a company, but for now we are evaluating whether the solution meets our client’s requirements. In initial tests, we are achieving very encouraging results.

Let’s consider paid support for our end customer. Thanks for help.

@danieldemoraisgurgel

The Date Modified for the folders working for rmount+winfsp (Windows) on the S3 compatible object store layer work correctly in this new version?

If you add directory_markers = true to your config

  --s3-directory-markers   Upload an empty object with a trailing slash when a new directory is created

Then directories will have a persistent date - otherwise they don’t actually exist.

I don’t think syncing directory modification times or metadata will work with directory_markers yet though. If you’d like to see this please open a new issue about it. If you are working on behalf of a company you might be interested in taking out a support contract and we could add that as part of it.

As an aside, I note that we aren’t testing bisync in the integration tests. If we wanted it to be tested it would need to appear here.

https://github.com/rclone/rclone/blob/8f0e9f9f6bd78f6ac7488ac48bbe7e9a9ba418ab/fstest/test_all/config.yaml#L1-L16

Should we? If we do want it then we can enable it after the v1.66 release as it will almost certainly have a lot of fallout trying bisync on all the different backends!

Just realizing I never responded to this part – yes, I think we should do that. It will keep us honest and give us the confidence to finally graduate bisync from beta.

And I agree about waiting until after the v1.66 release, as I fully expect all kinds of backend-specific oddities to appear! (My guess is most of them will be problems with the tests as opposed to the actual code being tested, but I could be wrong!)

Thanks for the notes @nielash . I’ll incorporate the feedback into the next revision when I’m back at my desk tomorrow (currently on a bus somewhere in France!). I’ll reply in detail then too.

WOW this is so exciting! It looks awesome. Can’t wait to take it for a test drive! 😄 🎉

For whatever it’s worth – I ended up creating this command for my personal use, and it is working beautifully for my purposes. You are right that it required adding a new optional interface, but once I did that, I was surprised at how minimal the other required changes were. About 8 lines of code each for local, drive, sftp, and crypt. A tiny change, but it packs a lot of punch 🙂

Wow, great work @nielash ! I’ve been wanting this functionality for so long and it appears that you’ve implemented support for it in a way that will work for me. I’m going to build your fork and give it a try but just from a cursory glance at the source, it looks like it will do exactly what I want. Thanks for sharing this!

I’m added simple example add metadata for local backend https://github.com/rclone/rclone/compare/master...lxShaDoWxl:rclone:master

I think for file level metadata, we can use --metadata option with rclone

Yes, but not for folders, so in the example above rclone and rsync would give different outputs.