Use rsync
com o sinal -c
( --checksum
), que compara arquivos por soma de verificação, em vez de tamanho e tamanho de modificação.
Exemplo
root@node51 [/tmp]# mkdir source
root@node51 [/tmp]# mkdir destination
root@node51 [/tmp]# echo "version 1" > source/file.txt
root@node51 [/tmp]# sleep 1
root@node51 [/tmp]# echo "version 1" > destination/file.txt
Observe que eu criei dois arquivos idênticos em dois momentos diferentes, mas suas somas de verificação são idênticas:
root@node51 [/tmp]# md5sum */file.txt
81127ad129dd2249f5ab0667ca0aeb84 destination/file.txt
81127ad129dd2249f5ab0667ca0aeb84 source/file.txt
root@node51 [/tmp]# stat */file.txt
File: 'destination/file.txt'
Size: 10 Blocks: 1 IO Block: 512 regular file
Device: 15h/21d Inode: 674358 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-08-10 13:14:12.710354355 -0500
Modify: 2016-08-10 13:14:12.710354355 -0500
Change: 2016-08-10 13:14:12.710354355 -0500
Birth: -
File: 'source/file.txt'
Size: 10 Blocks: 1 IO Block: 512 regular file
Device: 15h/21d Inode: 674234 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-08-10 13:14:07.198447196 -0500
Modify: 2016-08-10 13:14:07.198447196 -0500
Change: 2016-08-10 13:14:07.198447196 -0500
Birth: -
Usando rsync -avcP
:
root@node51 [/tmp]# touch source/file.txt
root@node51 [/tmp]# rsync -avcP source/ destination/
sending incremental file list
./
sent 87 bytes received 22 bytes 218.00 bytes/sec
total size is 10 speedup is 0.09
O arquivo não foi copiado.
Uma corrida diferente, usando rsync -avP
:
root@node51 [/tmp]# touch source/file.txt
root@node51 [/tmp]# rsync -avP source/ destination/
sending incremental file list
file.txt
10 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2)
sent 123 bytes received 35 bytes 316.00 bytes/sec
total size is 10 speedup is 0.06
O arquivo foi copiado.