How to RSYNC files between two servers?
Hello--can someone tell me how to RSYNC bteween two servers with IP addresses, username and passwords while removing the files at the senders end? Do I need to login as root on both servers? I appreciate your input.
|
Hi:
These links might help. http://www.tomsitpro.com/articles/li...t,2-777-4.html http://www.tecmint.com/sync-two-apac...s-using-rsync/ http://www.sysadminshare.com/2012/05...tween-two.html I don't know if you should be logged into both servers as root or not:- |
Hi,
you need to learn to use rm, rsync and (indirectly ssh). Eg to rysnc from server1 to server2 (with IP address 192.168.1.234), get a shell on server1, then run rsync. Eg. Code:
rsync -auv -e ssh somedir user2@192.168.1.234: Whether or not you need root depends on the permissions of the files in question. Evo2. |
Yes, thank you. It is slowing coming back to me now. But in your code, I believe that there are some missing parts. FYI: I am trying to write a crontab to do this automatically everyday. So, I am wondering about the following modifiers:
1. Rsync has a --remove-system-file modifier that I believe will remove files from Server 1, no? 2. I am wondering about how ssh will know the password of user2 in your example. Reading one of the links, I believe the ssh-keygen command enables this, no? How would the code combine to include both these command above? |
Hi,
your original post never mentioned anything about automating this. If you want this to be automated (eg with cron) you should probably use public key authentication (with the key unprotected by a passphrase). You can use ssh-keygen and ssh-copy-id to set it up. I'm not familiar with the --remove-system-file option and it is not documented in the rsync man page (on my Debian 8.0/ system). Evo2. |
Sorry, that should be --remove-source-files for Rsync. Where would I put that in your code? I am little unclear on whether that would retain older files on the destination folder (Server 2) that were previously deleted on the source folder (Server 1)?
In the links provided, the ssh-genkey is implemented separate from the Rsync code. But I remember including that in the code itself. I am setting up several crontabs to rsync between different external computers (Server 1 and Server 2, Server 1 and Server 3). I am a little worried about or unclear setting up multiple ssh-keys. I believe that the ssh-key could be implemented in the code. Is that correct? I have never heard of ssh-copy-id. How is that different than ssh-genkey? |
ssh-keygen & ssh-copy-id http://www.cyberciti.biz/faq/install...y-remote-host/
|
Hi,
Quote:
Quote:
Quote:
Quote:
Evo2. |
Quote:
Example: Code:
$ mkdir tempdir1 |
Great Example! Yes, indeed, rsync can be used for directories within a server, too. That was very clear Beryllos.
So far, my code has taken this shape: Code:
>rsync -rave --remove-source-files ssh remoteuser@remotehost:/remote/dir /this/dir/ Thanks guys! |
Hi,
Quote:
Code:
>rsync -rav -e ssh --remove-source-files remoteuser@remotehost:/remote/dir /this/dir/ Quote:
1. The private key (eg ~/.ssh/id_rsa) 2. The corresponding public key (eg ~/ssh/id_rsa.pub) The contents of the public key file needs to be put into the ~/.ssh/authorized_keys file (or similar) on the remote server. You can use the ssh-copy-id script to do this. Evo2. |
Thank you, Evo. That was very helpful. I am having one problem and have another question:
1. I am trying to rsync to synology, and the ssh-copy-id cannot write to the disk. Any suggestions? 2. How would I go about setting rsync and sshkey-gen on a third party linux box, where computer 3 accesses files from computer 1 and transfers them to computer 2? |
Hi,
Quote:
Quote:
Evo2. |
I assume that Synology is in reference to a NAS box.
Did you enable ssh/sftp via its control panel? Did you try copying the keys to a regular user (if any were created) or root? The .ssh directory may not exist or if copying to a regular user, home services is not enabled which allows regular users to access their home directories. |
Sorry. By Synology, I mean NAS. (I'm a true newbie.)
Here is my problem: when I do the following command, I get an error: >rsync -av -e ssh --remove-source-files /home/ftp_user/stage/datafolder root@75.36.201.198::backups/system/MachineName/stage root@75.36.201.198's password: Password: sending incremental file list datafolder/ rsync: failed to set times on "/system/MachineName/stage/datafolder" (in backups): Operation not permitted (1) datafolder/filename1.zip datafolder/filename2.zip rsync: mkstemp "/system/MachineName/stage/datafolder/.filename1.wv1RXC" (in backups) failed: Permission denied (13) rsync: mkstemp "/system/MachineName/stage/datafolder/.filename2.RfXual" (in backups) failed: Permission denied (13) sent 1891165115 bytes received 107 bytes 13753928.89 bytes/sec total size is 1890933885 speedup is 1.00 rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9] However, when I implement the same command using a directory (testfolder containing the same files) that I made by myself, I get no error. >rsync -av -e ssh --remove-source-files /home/ftp_user/stage/testfolder root@75.36.201.198::backups/system/MachineName/stage root@'s password: Permission denied, please try again. root@75.36.201.198's password: Password: sending incremental file list sent 33 bytes received 9 bytes 1.95 bytes/sec total size is 0 speedup is 0.00 Now, I thought there are permission issues as owners and groups of the directories and files contained within them. Previously the owner and group were ftp_user. But changing permissions to root for both owner and group did not solve the problem as illustrated above: >ls -als 4 drwxrwxr-x 2 root root 4096 May 15 17:35 testfolder 4 drwxr-xr-x 2 root root 4096 May 14 15:05 datafolder So, why is the folder "testfolder" that I made able to rsync, while the "datafolder" that was made by a shell script (that made the zip files) not able to rync? |
All times are GMT -5. The time now is 01:02 AM. |