Page 1 of 1

Verify if files have been copied correctly

Posted: Sat Apr 28, 2018 10:01 am
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:

Re: Verify if files have been copied correctly

Posted: Sat Apr 28, 2018 10:15 am
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.

Re: Verify if files have been copied correctly

Posted: Sat Apr 28, 2018 12:34 pm
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: