Verify if files have been copied correctly

Post Reply
Message
Author
User avatar
outlaw
Posts: 20
Joined: Thu Jul 13, 2006 6:35 pm

Verify if files have been copied correctly

#1 Post by outlaw »

I want to copy / transfer files from location to another then verify the files were copied correctly.

One technique to verify if a group of files has been copied correctly to another location would be to:
1) Create a archive of the files ... (tar, cpio or bz - whatever)
2) Create a md5sum for the archive then copy or transfer the archive to the new location.
3) Then create a new md5sum for the archive in the new location.
4) Use diff to compare the 2 md5sum files.

Can cp or another command be used to accomplish this task.
I need to copy all files in the specified directory and sub-directories.

Thanks in advance for any advice / suggestions offered.

Tom
Naturally nuts no pharmaceuticals required :happy:

User avatar
Adrian
Developer
Posts: 8266
Joined: Wed Jul 12, 2006 1:42 am

Re: Verify if files have been copied correctly

#2 Post by Adrian »

rsync checks md5 of the copied files use that, it also gives you nice option to update the copied files without having to copy all the stuff again.

User avatar
fehlix
Developer
Posts: 10366
Joined: Wed Apr 11, 2018 5:09 pm

Re: Verify if files have been copied correctly

#3 Post by fehlix »

If rsync together with md5-checksum does not fit into your file-transfer scenario
an alternative approach would be to recursively create a checksum file of that directory tree
and transfer this checksum file with the transfered files itself.
For checking file transfer success shortly after it took place
md5-checksum might sufficient. But as md5 does have a well-known collusion security-issue
I would not recommend using it for anything else. I.e. if you are going to verify
the checksum long time after the file transfer took place a better approach migth be to use sha256.
To use the more collusion-robust sha256 in combination with creating a hashsum tree
here en axample:

Code: Select all

# to get recursive hashsum-tool hashtree
# sudo apt-get install hashtree
# my source dir
DIR=My_Source_Dir
cd $DIR
sha256deep -lr . | tee $DIR.sha256
#
# to verify after transfer use
echo "sha256sum -c $DIR.sha256"
Happy hashing :happy:
Gigabyte Z77M-D3H, Intel Xeon E3-1240 V2 (Quad core), 32GB RAM,
GeForce GTX 770, Samsung SSD 850 EVO 500GB, Seagate Barracuda 4TB

Post Reply

Return to “XFCE Desktop Environment”