LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Help with rsync (https://www.linuxquestions.org/questions/linux-software-2/help-with-rsync-863089/)

ne0shell 02-16-2011 11:03 AM

Help with rsync
 
I consider myself fairly experienced w/ linux but rsync is just one of those apps I can't seem to make work. The man file and how to's all seem to either conflict or be missing something and when I can seem to get it working I run into strange errors.

I need to clone a directory of files and folders to another server. The folder to be copied is the "public_html" folder on the remote server, my goal being to copy it completely to a folder with the same name on my local server:

Here's my rsync command -

rsync -r -a -v -e "ssh -l user" domain.com:/public_html /home/user/public_html

I get an error related to a stat failure of some kind (I don't have the error in front of me right now)

What am I doing wrong?

corp769 02-16-2011 11:07 AM

Can you post the full output of the error you are getting?

arizonagroovejet 02-16-2011 11:42 AM

Yeah you need to post the error. Your use of -r is redundant because it's implied by using -a. I've never seen someone use -e before, so I've no idea if that's the correct way to use it. I'd use

Code:

$ rsync -av user@domain.com:public_html/ /home/user/public_html/
Note the lack of a / between the : and public_html.

Code:

:/public_html
means a directory called public_html in the root directory of domain.com

Code:

:public_html
means a directory called public_html in the home directory of the user you're connecting to domain.com as

If there are files already in the destination they'll still be there after you run rsync which means the contents of both directories will not be identical. If you want to make an exact copy of what's in the remote directory then use

Code:

$ rsync -av --delete user@domain.com:/public_html/ /home/user/public_html/
Which will delete any files in the destination which are not in the source directory. Use with caution.

You may want to add the --dry-run option to any command the first time you use it as that will show you what will be done but don't actually do it.

szboardstretcher 02-16-2011 11:42 AM

Quote:

Originally Posted by ne0shell (Post 4260435)
I consider myself fairly experienced w/ linux but rsync is just one of those apps I can't seem to make work. The man file and how to's all seem to either conflict or be missing something and when I can seem to get it working I run into strange errors.

I need to clone a directory of files and folders to another server. The folder to be copied is the "public_html" folder on the remote server, my goal being to copy it completely to a folder with the same name on my local server:

Here's my rsync command -

rsync -r -a -v -e "ssh -l user" domain.com:/public_html /home/user/public_html

I get an error related to a stat failure of some kind (I don't have the error in front of me right now)

What am I doing wrong?

Without any output, as requested by the other poster, I would say that trying this *might* help:

Code:

rsync -raveh --progress user@domain.com:/public_html/ /home/user/public_html/

if you still get an error, paste the output of this:

rsync -ravvvvvvveh --progress user@domain.com:/public_html/ /home/user/public_html/

Sorry, started typing this before the previous post was there.

ne0shell 02-16-2011 01:15 PM

Quote:

Originally Posted by arizonagroovejet (Post 4260491)
Yeah you need to post the error. Your use of -r is redundant because it's implied by using -a. I've never seen someone use -e before, so I've no idea if that's the correct way to use it. I'd use

Code:

$ rsync -av user@domain.com:public_html/ /home/user/public_html/
Not the lack of . between the : and public_html.

Code:

:/public_html
means a directory called public_html in the root directory of domain.com

Code:

:public_html
means a directory called public_html in the home directory of the user you're connecting to domain.com as

If there are files already in the destination they'll still be there after you run rsync which means the contents of both directories will not be identical. If you want to make an exact copy of what's in the remote directory then use

Code:

$ rsync -av --delete user@domain.com:/public_html/ /home/user/public_html/
Which will delete any files in the destination which are not in the source directory. Use with caution.

You may want to add the --dry-run option to any command the first time you use it as that will show you what will be done but don't actually do it.

See, I wasn't aware of how exactly to set the destination directory and thought it was going by the directory my shell was currently in. The full path on the local server is more like - /home/user/public_html. user@domain.com is the SSH account on the remote server, at least that's what I thought it was for.

szboardstretcher 02-16-2011 01:26 PM

rsync [options] from to

if you want to rsync from your local computer to a remote host, then you would do this:

Code:

rsync -varh --progress --delete /home/user/public_html/ user@domain.com:/public_html/
which translates to:

synchronize (verbose, archive, recursive, human readable, with progress indicator. Delete any remote files deleted from source.)FROM: /home/user/public_html/ TO: user@domain.com:/public_html/

If it happens to be over a wan link, you might save time by adding the -z compression option as well.

Quote:

rsync -varzh ...etc...

arizonagroovejet 02-16-2011 01:29 PM

I just edited my post, the line starting 'not the lack' had at least three mistakes in it. :(

Quote:

Originally Posted by ne0shell (Post 4260602)
See, I wasn't aware of how exactly to set the destination directory and thought it was going by the directory my shell was currently in. The full path on the local server is more like - /home/user/public_html. user@domain.com is the SSH account on the remote server, at least that's what I thought it was for.

I'm a bit confused now as to whether you're confused or not. To be clear, the basic syntax is

Code:

$ rysnc source destination
Source being where you want to copy from and destination is where you are copying to.

In your example the source is a directory on domain.com. If you prefix the directory with / it is considered to be an absolute path. So if you use this as the source
Code:

bob@domain.com:/public_html
the that means, well exactly what it says really. The directory called public_html in the root directory of the filesystem on domain.com. Where as if you use
Code:

bob@domain.com:public_html
that means the directory called public_html that's in the home directory of the user called bob on domain.com.

It's the difference between using a relative and an absolute path. If you don't know the difference between absolute and relative paths, you really ought to make sure you understand that before doing anything else. Basically if it starts with / then it's absolute. For more info see http://en.wikipedia.org/wiki/Path_%28computing%29 or probably many other places.

sneakyimp 02-16-2011 01:31 PM

Not sure, but i think ne0shell might be confused about the use of slashes. If you start a path with a "/" then you are specifying an absolute path from the root of your file system. If your current working directory is /home/user, then when you refer to "public_html" (without a slash) then that is NOT the same thing as "/public_html" with the slash. If you have a folder located at /public_html on your file system, it's probably because you accidentally added a leading slash in your rsync command.

ne0shell 02-16-2011 07:39 PM

See how confusing this stuff gets? I want to copy a remote folder to my local server, not the other way around.

Let me try this again. I need to copy the remote folder from path /home/user/public_html to my local server path /home/user/public_html using the ssh account user@domain.com for the remote machine. (I am logged in as root on the local server and do not have root on the remote server).

sneakyimp 02-16-2011 08:17 PM

Using the complete paths in both cases is much more likely to get you want. If you use a partial/relative path, then the copy locations would depend on the current working directory of whoever executes the command. If you were running is root, this might be /home/root/public_html or something like that.

You don't necessarily need root access on both servers. On the SOURCE server, you need read permission for all the files and directories to be copied. On the DESTINATION server, you need write permission for all the files and directories to be copied.

ne0shell 02-16-2011 08:45 PM

Quote:

Originally Posted by sneakyimp (Post 4260960)
Using the complete paths in both cases is much more likely to get you want. If you use a partial/relative path, then the copy locations would depend on the current working directory of whoever executes the command. If you were running is root, this might be /home/root/public_html or something like that.

You don't necessarily need root access on both servers. On the SOURCE server, you need read permission for all the files and directories to be copied. On the DESTINATION server, you need write permission for all the files and directories to be copied.

What would the proper command syntax be then if I use full paths?

sneakyimp 02-16-2011 08:57 PM

Depends on which machine you run the command from. Are you running it from the SOURCE machine or the DESTINATION machine?

ne0shell 02-16-2011 09:45 PM

Quote:

Originally Posted by sneakyimp (Post 4260997)
Depends on which machine you run the command from. Are you running it from the SOURCE machine or the DESTINATION machine?

You really should read the thread as I've said this several times - I'm running the command on the destination server. The source server is remote.

sneakyimp 02-16-2011 09:57 PM

*You* should really read this thread as all the information you need has been supplied already. Or read the man pages on rsync:
Code:

$prompt: man rsync

ne0shell 02-17-2011 12:48 AM

Quote:

Originally Posted by sneakyimp (Post 4261040)
*You* should really read this thread as all the information you need has been supplied already. Or read the man pages on rsync:
Code:

$prompt: man rsync

I don't mean any offense but if you jump into a thread you should at least read the previous posts.

None of the information given so far in the thread helps, unfortunately - it looks like most assumed the transfer was going in the opposite direction and my entire reason for posting the question here is that the man page for rsync is not clean and is not helping me solve the issue.


All times are GMT -5. The time now is 05:01 PM.