How do you compare two folders and copy the difference to a third folder in a remote server?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do you compare two folders and copy the difference to a third folder in a remote server?
# 1  
Old 09-26-2016
How do you compare two folders and copy the difference to a third folder in a remote server?

How do you compare one local folder and a remote folder and copy the difference to a third folder in a remote folder.e.g.

Code:
Folder A -- Is in a remote server and it has the following files

TEST1.OUT
TEST2.OUT
TEST3.OUT

Folder B --Is in a local server and it has the following files

TEST1.OUT
TEST2.OUT
TEST 3.OUT
TEST4.OUT
testtest123.out

comparison is done based on timestamp.


THIRD Folder - Holds new files that are not in remote server

TEST4.OUT
testtest123.out

# 2  
Old 09-27-2016
Your question is unclear: First, you say that you compare by timestamp, and then you say that you want to copy only files that are not on the remote server. For example, if TEST2.OUT on the local server is younger than TEST2.OUT on the remote server, should it be copied or not?

In any case, have a look at rsync.
# 3  
Old 09-27-2016
How can you use rsync to compare local directory and remote directory and then copy the difference to a new directory in remote serve?

E.g I can't get it to work with this command.


Code:
rsync -rvcm --compare-dest=/tmp/test server.com:/tmp/test server.com:/tmp/difference

Moderator's Comments:
Mod Comment Please use correct CODE tags ([CODE], not <code>)
as required by forum rules!

Last edited by cumeh1624; 09-27-2016 at 08:03 PM.. Reason: Changed CODE tags.
# 4  
Old 09-27-2016
It's rsync, not Rsync.

The comparing is done implicitly, so you don't need a separate comparision step. You basically just do a rsync source destination, and rsync figures out by itself, what it needs to copy. To specify, what are the exact conditions, under which a file should be copied, is defined by the options which can be passed to rsync.

Last edited by rbatte1; 09-27-2016 at 12:48 PM.. Reason: Converted CODE tags to ICODE tags
# 5  
Old 09-27-2016
I know how to use rsync to sync up remote destination folder but my requirement is to compare files in local directory to files in remote directory and copy the difference to another directory in same remote server named difference.

That's why I gave an example of a rsync command, I need an example command on how this can be accomplished.

e,g,

Code:
rsync -rvcm --compare-dest=/tmp/test server.com:/tmp/test server.com:/tmp/difference

Any help is highly appreciated.
# 6  
Old 09-28-2016
Quote:
Originally Posted by cumeh1624
I know how to use rsync to sync up remote destination folder but my requirement is to compare files in local directory to files in remote directory and copy the difference to another directory in same remote server named difference.
You mean: You have a local directory A, and remote directories B and C, and want to copy those files in A to be copied to C, which are different from B? Sorry to misunderstand you.

In this case you indeed need to rule out your own algorithm, but unless I overlook something, you haven't answered yet my earlier question, how you exactly define "difference". Content? Last modification time?

You still can use rsync for getting the difference. Please look at the --dry-run switch of rsync. The idea is to first do a dry run of rsync of A vs. B, collect from it the names of the files which would be copied, and then use this list to actually copy the files to B, using for instance scp or rcp.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy local files to single remote host but multiple folders using rsync

I'm trying to copy a file myfile.scr from my local Linux server to multiple folders on remote AiX server using single rsync command. Below command helps me copy the file "myfile.scr" from my localhost to a remote host folder "/app/deployment/tmpfiles" rsync --delay-updates -F --compress... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Compare Directories and folders on two remote lpar

Hello, i'm trying to script to compare the same directory on the lpar. The problem is i'm using the command : find /etc -type d -ls but i cannot reach the remote lpar. I have another solution to put that command in a text file and compare with Excel. but i could be fine to have the... (7 Replies)
Discussion started by: steiner
7 Replies

3. Shell Programming and Scripting

Linux Script to compare two folders and copy missing files

Hi, I need help in shell scripting. If someone can help me, that would be great! Problem. I want Linux Script to compare two folders and copy missing files. Description. I have two directories /dir1 /dir2 I need to copy all distinct/new/unique/missing files from /dir1 and that... (1 Reply)
Discussion started by: S.Praveen Kumar
1 Replies

4. Shell Programming and Scripting

Copy folder and files from unix server to linux server

We would be migrating unix solaries to Linux redhat. Basically source is unix and target is linux. i would like to copy entire file system unix/source/* to target linux/souce/* but target linux has only folder setup so what ever files copied need to be placed in the linux server with same... (8 Replies)
Discussion started by: balajikalai
8 Replies

5. Shell Programming and Scripting

HELP! Need to compare 2 folders on 2 different systems, and copy unmatched filenames to other folder

This has been tearing my hair out. I need to: 1: compare server1:/data/archive/ to server2:/data/archive/ (through rsync, ssh, etc) 2: filenames that don't match, get copied (scp) to server2:/data/ server1 and server2 have ssh, scp, rsync access between eachother. Is there any option in... (3 Replies)
Discussion started by: damang111
3 Replies

6. Shell Programming and Scripting

Find files of type within folder copy multiple results to different folders

Ok question number two: I'd like to search a directory for multiple file types (rar, txt, deb) and depending on what's found, copy those files to folders named Rar, TextFiles, and Debs. I'm looking for speed here so the faster the script the better. I want it to be a function that I pass 1 argument... (4 Replies)
Discussion started by: DC Slick
4 Replies

7. UNIX for Advanced & Expert Users

How to copy folder from one server to remote one using SSH

ok guys. I have a Centos server running a large website I own. Its is severely struggling under the load and I am having to move to a new load balanced setup. The servers are both remote (to me) and although I can do most things admin wise in nix, I am struggling a bit to come up with a way... (1 Reply)
Discussion started by: anderow
1 Replies

8. Shell Programming and Scripting

copy some files from users home folders to my folder

i have users home directories in /home all the users have some files starting with character e and i want to copy all these files in a folder in my (root) home using a script i tried the script for i in m5 do cd m5 cp e1* /home/pc/exam cd .. done but get these... (3 Replies)
Discussion started by: pcrana
3 Replies

9. Shell Programming and Scripting

Remote compare of folders

Hi, Is there a way (either commands/tools/scripts/logic) to compare two given folders on different unix boxes. I want to compare folder a in Unix box 'A' with folder 'b' in Unix box 'B'. I can run the script in Unix box 'A'. I am looking. for following results: files/sub folders only in a... (1 Reply)
Discussion started by: sunilav
1 Replies

10. UNIX for Dummies Questions & Answers

How to compare the difference between a file and a folder??

Hi, I have a .txt file which has to be compared with a folder and print the difference to some other .txt file. I did try with the diff command..i mean diff /tmp/aaa/bbb.txt /space/aaa/bbb/ /***bbb.txt contains all the files names which may or may not exist in the folder bbb..so i need... (2 Replies)
Discussion started by: kumarsaravana_s
2 Replies
Login or Register to Ask a Question