Grsync - archive maintaining folder & file dates

Hi
I have a huge number of music files to move from a USB external HDD to a new NAS drive.
I use Emby as my media server and store my music thus:

Artist

  • Album 1
  • Album 2

I like Emby to display the music with the most recently added albums first.

Trying to use Grsync to move the files, did a sample first and have set the Preserve Time flag.

When I run the process the top level folder ie Artist has the correct date, but the subfolders ie the albums have the date of creation ie TODAY.

How do I force Grsync to recursively set the dates for all folders?

Thanks in advance.
Screenshot_2025-03-21_17-41-21

If you decide to follow my suggestions PLEASE HAVE BACK-UP’s first

That is one reason I don’t use Grsync, don’t read this as rant on Grsync but the Date issue was a show stopper for me.

Create directories and set their dates:

mkdir d1 d2
touch -d 'yesterday' d1

Copy the directory using rsync:

rsync -i -avR d1 d2

Override the date on the copied directory and run rsync again:

touch d2/d1
rsync -i -avR d1 d2

This process will ensure that the modification times are preserved and corrected if they are altered. Additionally, you can use the –info=progress2 option to get detailed output and ensure that the dates are being preserved correctly. Thats my method, I like to see.

If your interested I would use some thing like this:

rsync --progress --files-from=<\(find /src_path -mtime -3 -type f -exec basename {} \;\) /src_path/ /dst_path

This command will sync files that were modified within the last three days.

find /path/to/directory -type d -exec touch -d 'yesterday' {} \;

This command will set the modification time of all directories under /path/to/directory to yesterday’s date.

I won’t be around much today so I’ll check back , and Good Luck. :slight_smile:

I had to check my suggestion:

Location: /tank/d2/Robert Plant - 2007 - Greatest Hits (3CD)/RobertPlantCD1

Created:Today

Modified:06/22/2024

Accessed:Today 

date -r '/tank/d2/Steppenwolf - Discography 1968-2005 (FLAC) 88/1968 - Steppenwolf/01 - Steppenwolf.flac' 
Mon Dec 16 10:28:35 AM MST 2024

Same file:

stat  '/tank/d2/Steppenwolf - Discography 1968-2005 (FLAC) 88/1968 - Steppenwolf/01 - Steppenwolf.flac' 
  File: /tank/d2/Steppenwolf - Discography 1968-2005 (FLAC) 88/1968 - Steppenwolf/01 - Steppenwolf.flac
  Size: 21828004  	Blocks: 42665      IO Block: 131072 regular file
Device: 0,99	Inode: 820231      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/      me)   Gid: ( 1000/      me)
Access: 2025-03-21 14:47:26.423399041 -0600
Modify: 2024-12-16 10:28:35.023499879 -0700
Change: 2025-03-21 14:15:04.680830530 -0600
 Birth: 2025-03-21 14:15:04.624831565 -0600

I have not used Grsync but is it not possible to add parameters under Advanced or Extra options to preserve these additional timestamps?

If I run grsync with elevated privileges it will preserve Times

As root I ran (I’m not suggesting @arst06d you do this) but:

stat '/tank/Music/Robert Plant - 2007 - Greatest Hits (3CD)' 
  File: /tank/Music/Robert Plant - 2007 - Greatest Hits (3CD)
  Size: 9         	Blocks: 3          IO Block: 512    directory
Device: 0,99	Inode: 999905      Links: 6
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2025-02-16 13:25:47.045766717 -0700
Modify: 2025-03-21 11:07:11.036438854 -0600
Change: 2025-03-21 15:03:58.495627561 -0600
 Birth: 2024-11-06 15:14:09.377499723 -0700

I just don’t use many GUI’s for this reason, I love CLI :two_hearts:

Hopefully a Dev has an explanation.

g1

g2

In my short experience with Grsync … yes there is such setting

BUT Like @1fallen I had to do , I did exactly the same as he demonstrated (root access) using the GUI.

Which caused me to go to the CLI with rsync vs the GUI front end … (which honestly for me was actually easier, but that may not be the case for the OP)

But that is not a real solution for the OP as they seem to use a GUI vs a CLI which I understand.
Not everyone likes the CLI

1 Like

Thanks to all for the help so far.
To be honest, I’m not confident with the nitty gritty - hence the comfort of the GUI.
There are options/spaces to put extra flags/commands to be run before/during/after the main command - see the additional screenshots.
Any further
Screenshot_2025-03-21_22-59-24
Screenshot_2025-03-21_23-00-00
guidance greatly appreciated.

Well, somehow my fiddling appears to have worked - just had a successful completion of a small subset of data with Grsync.
To be honest I didn’t change anything in Grsync, just created a new destination folder on the NAS.
Absolutely clueless as to why it worked. I shall try a few more small tests before committing to a full run.
I’ll leave this open for now - wish me luck!

And the timestamps were preserved as you want?

Fingers crossed.

Yes, on the several test folders/subfolders I ran.
I am taking the plunge and currently running the full process. It may take a while, but I can see the timestamps gradually being updated as the process progresses.

First there are other methods to do the same adjustment, but for simplicity I’ll use visudo for this post:

sudo visudo

Now add this to it:

<username> ALL= NOPASSWD:/usr/bin/rsync

Replace <username> with the login user name, example of mine:

@includedir /etc/sudoers.d
me ALL= NOPASSWD:/usr/bin/rsync

Save and close the file. That should take care of your dates.

Thanks very much. However, as stated above Grsync appears to be taking care of business. Just letting it run.

Just offering another method is all! :wink:
Have fun.

And very much appreciated - but, to be completely honest, I have no idea what your solution actually does. It looks like it’s creating a file but then I’m lost.

It allows rsync/grsync to run without using sudo

No it edit’s an existing file, the file is already there your just adding to it.
The whole kit and caboodle look like:
BTW You really have to be careful adding things to that file, it can ruin your whole day if done wrong. Just a Heads-up.


[details="Summary"]
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults	env_reset
Defaults	mail_badpass
Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# This fixes CVE-2005-4890 and possibly breaks some versions of kdesu
# (#1011624, https://bugs.kde.org/show_bug.cgi?id=452532)
Defaults	use_pty

# This preserves proxy settings from user environments of root
# equivalent users (group sudo)
#Defaults:%sudo env_keep += "http_proxy https_proxy ftp_proxy all_proxy no_proxy"

# This allows running arbitrary commands, but so does ALL, and it means
# different sudoers have their choice of editor respected.
#Defaults:%sudo env_keep += "EDITOR"

# Completely harmless preservation of a user preference.
#Defaults:%sudo env_keep += "GREP_COLOR"

# While you shouldn't normally run git as root, you need to with etckeeper
#Defaults:%sudo env_keep += "GIT_AUTHOR_* GIT_COMMITTER_*"

# Per-user preferences; root won't have sensible values for them.
#Defaults:%sudo env_keep += "EMAIL DEBEMAIL DEBFULLNAME"

# "sudo scp" or "sudo rsync" should be able to use your SSH agent.
#Defaults:%sudo env_keep += "SSH_AGENT_PID SSH_AUTH_SOCK"

# Ditto for GPG agent
#Defaults:%sudo env_keep += "GPG_AGENT_INFO"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root	ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo	ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "@include" directives:

@includedir /etc/sudoers.d
me ALL= NOPASSWD:/usr/bin/rsync

[/details]

A different solution you could use is adding a polkit action which would allow a specific application or command line tool to run. It would be named in reverse domain order (e.g. net.sourceforge.grsync.policy to match where the development is done) and placed in /usr/share/polkit-1/actions and look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/polkit/policyconfig-1.dtd">
<policyconfig>

  <action id="net.sourceforge.grsync.policy">
    <message>Authentication is required to run grsync</message>
    <icon_name>grsync</icon_name>
    <defaults>
      <allow_any>yes</allow_any>
      <allow_inactive>yes</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/grsync</annotate>
    <!--annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate -->
  </action>

</policyconfig>

This makes it so any execution done with pkexec will not require a password. This is a preferred method of launching from the command line as GUI tools will not respect the Desktop Environment without this.

Typically this would have to be included with the packaging or by the upstream developer, but neither of these things are done, likely because having root write access isn’t something typically done with this tool.

That said, I don’t use it, so your mileage may vary.

1 Like

@1fallen and @eeickmeyer

From a basic user point of view and just for clarity:

These two different methods only apply to running rsync or grsync without sudo privileges, correct?

And…does doing so resolve the issue of timestamps which is what the OP originally wanted to deal with?

@1fallen @eeickmeyer
Many thanks for the further education, which increases my fear of the terminal commands exponentially :scream:!

Correct! :wink:

Yep, it will, as seen on TV… :rofl:

1 Like

It might seem scary at first but you will grow more comfortable with it over time.

The best part is that we have amazing people here on Discourse who can help explain things.

1 Like

I’ve stood on the shoulder’s of Giants for years…and yes the fear will subside in time. :wink: But it is your best friend at the end of day…:slight_smile:

1 Like