HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Need to compare files in different server

 
boomerang
Frequent Advisor

Need to compare files in different server

Hi Admins,

I need to compare details like size,file name & permission of files from production with DR.Please suggest me the most easiest methods to compare the files in different server when the file count is huge.

Thanks in advance
9 REPLIES
Michael Steele_2
Honored Contributor

Re: Need to compare files in different server

Hi

'chksum' will be only one line and easy to read, if you get the same equal result on both files then the files are exact. 'diff' will be a huge report but you can pipe the stderr to null and just test the "$?" for > zero. And you'll probably want remsh or ssh -l configured for remote login and remote command execution. This is probably already set up.

Put them all in a script after configuring the remote execution using a input file read by both.

cat input_file | while read a
do
remsh cksum $a
done > output_file

Support Fatherhood - Stop Family Law
Hakki Aydin Ucar
Honored Contributor

Re: Need to compare files in different server

Hi

you can also use wc that shows also total like these :

# wc tmp1 tmp1
89 89 5251 tmp1
89 89 5251 tmp1
178 178 10502 total


# remsh host1 "wc /path_to_file1/tmp1 /path_to_compare/tmp2"
89 89 5251 /path_to_file1/tmp1
239 239 14101 /path_to_file1/tmp2
328 328 19352 total

Hakki Aydin Ucar
Honored Contributor

Re: Need to compare files in different server

Hi

another concept is to use ll OR ls -l UX command ;

# remsh host1 "ll /path/tmp1 /path/tmp2 > /tmp/oku"
# cat /tmp/oku |awk {'print $5,$6,$7,$8,$9'}
5251 Mar 18 2008 /path/tmp1
14101 Mar 18 2008 /path/tmp2
Steven Schweda
Honored Contributor

Re: Need to compare files in different server

> I need to compare details like size,file
> name & permission [...]

What about the contents of the files?

"ls -lR" would show those meta-data, but not
the file contents.

> 'chksum' will be only one line [...]

"cksum" of _what_ "will be only one line"?

> [...] remsh or ssh [...]

NFS might be simpler.

The value of different comparison methods
tends to depend on factors which are still
unknown, like how good the network connection
is between these systems, and exactly what
you wish to compare.

> [...] the file count is huge.

> remsh cksum $a

One "remsh" per file probably wouldn't be my
first choice of methods.
Steven Schweda
Honored Contributor

Re: Need to compare files in different server

Have you looked at "rsync"? I don't use it,
so I know nothing, but the "-n" option:

-n, --dry-run perform a trial run with no changes made

might be useful for comparisons.


How are you getting these data to the DR
system in the first place? "rsync" could be
useful for more than just comparisons.
boomerang
Frequent Advisor

Re: Need to compare files in different server

Hi All,

Thanks for your valuable suggestions

Hi Steven,

I need to identify differences between 2 directory which are in different server(prod & DR).

what all things to be compared?
1.Ownership(user and group)
2.Permission
3.File name,content & size

and have to list missing files which are in prod and not in DR.

Victor Fridyev
Honored Contributor

Re: Need to compare files in different server

I understand that the solution below is not elegant, but try to run on both servers:
cd DIRNAME
find . -exec ls -1 {} \; | while read F; do
echo "$F $(/bin/ls -l $F | awk '{print $1,$3,$4}') $(sum $F)"
done| sort > $DIRNAME.out

The .out files contain all or almost all requested parameters. Diff the files from both computers.

Additional question: Why do you need this ? If you need to synchronize two machins, rsync is the best solution, as it was mentioned earlier.

HTH
Entities are not to be multiplied beyond necessity - RTFM
Steven Schweda
Honored Contributor

Re: Need to compare files in different server

If you're looking for simple, and if NFS is
available, then a plain "diff -R" would tell
you about the file contents, and a "diff"
between "ls -lR" reports would tell you the
rest. It would make some sense not to worry
about the date-time values on directories, so
a little more work to eliminate those would
be useful.

If the network is slow, or if NFS is not
available, then you should be able to use
"find" and "chksum" (and "diff") to test for
mismatched file contents without copying
everything across the network.

Are you looking for ideas, or were you
waiting for someone to write a script for
you?

> [...] rsync is the best solution [...]

Nah, that was a five-point answer.
boomerang
Frequent Advisor

Re: Need to compare files in different server

thanks for your suggestions.