LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   synchronize using rsync (https://www.linuxquestions.org/questions/linux-networking-3/synchronize-using-rsync-777260/)

cccc 12-21-2009 11:16 AM

synchronize using rsync
 
hi

Howto synchronize a directory included all subdirectories between 2 linux machines (POWERPC)?

tom4everitt 12-21-2009 11:33 AM

Basically

rsync -r local_dir user@othercomputer:dir_on_other_machine

or, if you want to sync in "the other direction", you can just switch the arguments to:

rsync -r user@othercomputer:dir_on_other_machine local_dir

cccc 12-25-2009 09:02 AM

Thx, but I have a questions:

How it works to transfer user rights and permissions as well?

tom4everitt 12-26-2009 02:53 AM

Then you should use the -a option instead of -r (a is for archive, r is for recursive). So what you write is:

Code:

rsync -a local_dir user@othercomputer:dir_on_other_machine

rsync -a user@othercomputer:dir_on_other_machine local_dir

also, beware of appending a slash to your 'from folder'. Its hard to explain the difference, but if you try to sync a folder with and without the slash, I think you'll get it.


EDIT:

You might wanna add the -u option as well, so that it doesn't copy files that have a newer modified time in the 'to directory'. Depends how you're going to use it I guess.

cccc 12-26-2009 05:13 AM

Thx, I've already done the following:
Code:

# rsync -e ssh -avzp --delete-after /support/ root@192.168.2.23:/support/
Do u think is not OK?

Should I better do this?
Code:

# rsync -e ssh -rvzp --delete-after /support root@192.168.2.23:/support

colucix 12-26-2009 06:59 AM

Quote:

Originally Posted by cccc (Post 3805063)
Do u think is not OK?

Should I better do this?

There is no a better or worse solution for us. It all depends on what do you want to achieve. If you want to have an exact copy of your original directory, including permissions, ownership, modification times and so on... you need the -a archive option. If you want to add verbosity use the -v option. If you want to compress data during the transfer use -z.

Read carefully the rsync help or the manual page: then you will be aware that -a equals to -rlptgoD and that you can avoid some redundancy in your command line options.

cccc 12-26-2009 07:03 PM

Quote:

Originally Posted by tom4everitt (Post 3804980)
also, beware of appending a slash to your 'from folder'. Its hard to explain the difference, but if you try to sync a folder with and without the slash, I think you'll get it.

I don't know what u exactly mean.
Can u pls give some more details and an example?

THX

tom4everitt 12-27-2009 04:30 AM

Quote:

Originally Posted by cccc (Post 3805525)
I don't know what u exactly mean.
Can u pls give some more details and an example?

THX

Okay, let me try to explain it then :P

If you have a folder foo containing files a1, a2, a3, that you want to copy to another folder bar, then if you do:

rsync -r foo/ bar

bar will end up containing a1, a2, a3.

If you instead do:

rsync -r foo bar

bar will end up containing a folder named foo which in turn contains a1, a2, a3.

So appending a / or not too foo makes quite a difference. As long as you stick to one of the options you'll be quite safe, but it's important to know there's a difference (the cp command does not care about an appended slash).

Skaperen 12-27-2009 08:58 AM

It all depends on whether you want to put the source folder INSIDE the target folder, or put its CONTENTS inside the target folder. The traditional Unix logic used on the "cp" command depends on whether the target folder already exists or not.

The simple command "cp -r foo bar" (assuming "foo" exists and is a directory) will behave differently if "bar" does not exist, than if "bar" does exist (and is a directory). This behavior can be changed by appending "/." to the source directory. The effect of doing that is that you are changing the final name component of the source directory from "foo" to ".". It is that last name component that is the target inside "bar". But since "." names the directory it is in, the effect is that the source and target are peers and the source contents become the target contents.

The "rsync" command changes this somewhat by allowing appending just "/" (though "/." also works) to have the effect of making the source and target directories be peers.

You have to decide whether you want the source directory to be put INSIDE the target directory, or to just merge the source directory contents into the target directory contents. You must make this decision if the target exists. If the target does not exist, then it will always make the target as an equivalent to the source. You append the "/" or "/." or not, as appropriate. I always recommend using "/." instead of "/" in the case where appending them is desired, since "/." works on other commands like "cp", too (e.g. you only have to remember to append "/." for whatever command is used for copying).

cccc 12-27-2009 10:53 AM

THX

tom4everitt 12-28-2009 03:35 AM

Quote:

Originally Posted by Skaperen (Post 3805887)
It all depends on whether you want to put the source folder INSIDE the target folder, or put its CONTENTS inside the target folder. The traditional Unix logic used on the "cp" command depends on whether the target folder already exists or not.

The simple command "cp -r foo bar" (assuming "foo" exists and is a directory) will behave differently if "bar" does not exist, than if "bar" does exist (and is a directory). This behavior can be changed by appending "/." to the source directory. The effect of doing that is that you are changing the final name component of the source directory from "foo" to ".". It is that last name component that is the target inside "bar". But since "." names the directory it is in, the effect is that the source and target are peers and the source contents become the target contents.
.

Aah, interesting. I didn't know this.


All times are GMT -5. The time now is 11:58 AM.