I have an issue with files attributes since I changed my company's file system from an old ubuntu 12 to a Synology NAS.
I initially mounted NFS shares on my old file system, then with cp I copied everything, everything was ok But i forgot to preserve the attributes, and we lost especially the date, the dates became the copy date, and not the real date.
I found the rsync command rsync -vrt --size-only /src /dest But some files have been modified since the copy, and the command overwrite them...
For example i tried to create a file on the old file system, copying it on the new synology then modifiyng the file on synology. When i use rsync, the file is erased and replaced by an old version.
I am looking for a command, to copy timestamps for files only when the file have exactly the same size (haven't been modified)
No mater if it takes long time
Edit :
I tried the proposed solution with a test directory, no error but no any changes:
old_base=/home/samba/shares/projects/test
new_base=/mnt/NAS
cp $old_base $new_base -rv
`/home/samba/shares/projects/test/1201.txt' -> `/mnt/NAS/test/1201.txt'
`/home/samba/shares/projects/test/test.txt' -> `/mnt/NAS/test/test.txt'
`/home/samba/shares/projects/test/1200.txt' -> `/mnt/NAS/test/1200.txt'
`/home/samba/shares/projects/test/1202/1202.txt' -> `/mnt/NAS/test/1202/1202.txt'
Now my new base is the same with the old, but no timestamp like the reality
I modify one file, adding content to simulate a file edited since i copied everything
Then i apply your solution :
root@xx:/mnt/NAS/test# cd $old_base; find . -type f | xargs ls -s | sort -k 2,2 >/tmp/old
root@xx:/home/samba/shares/projects/test# cd $new_base; find . -type f | xargs ls -s | sort -k 2,2 >/tmp/new
root@xx:/mnt/NAS# comm -12 /tmp/old /tmp/new | while read size filename; do touch ${new_base}/${filename} -r ${old_base}/${filename}; done
comm: file 2 is not in sorted order
comm: file 1 is not in sorted order
I have no error, but no any changes
(i am not sure what do you mean by ${filename} but i also tried to replace it by ${new_base}/*
Edit : 22/07
I have no any result when i use
comm -12 --nocheck-order /tmp/old /tmp/new