Thursday, March 5, 2009

comaring md5sum for a directory

Suppose you have a BOOKS directory and you want to backup it and check using md5sum for the integrity of the backup. So first you have to make md5sum of your original BOOKS directory as follows:

$find BOOKS/ -type f -print0 | xargs -0 md5sum > checksum.md5

then you copy checksum.md5 to the directory in which backup BOOKS directory exists. Now run this command to check the integrity

$md5sum -c checksum.md5

or if the files are too many then

$md5sum -c checksum.md5 |grep FAILED

put the errors in a file and use find and replace of any editor to remove ": FAILED" and then againn copy for good files. Repeat the process until everything is alright.

$md5sum -c checksums_backup.md5 |grep FAILED|grep /tmp/x.txt
$for i in `cat /tmp/x.txt`; do echo "$i" ;cp oldDir/$i backupRootDir/$i -v; don
e

And to check that whether a new file is added or som old one is deleted you can always run the diff and comm command.

reference http://info.michael-simons.eu/2008/10/25/recursively-md5sum-all-files-in-a-directory-tree/

No comments: