CentOS5 + rsync Synchronize files on two servers

Source: Internet
Author: User
Document directory
  • Always use rsync over ssh
  • Rsync command common options
  • Task: Copy file from a local computer to a remote server
  • Task: Copy file from a remote server to a local computer
  • Task: Synchronize a local directory with a remote directory
  • Task: Synchronize a remote directory with a local directory
  • Task: Synchronize a local directory with a remote rsync server
  • Task: Mirror a directory between my "old" and "new" web server/ftp

Always use rsync over ssh

Since rsync does not provide any security while transferring data it is recommended that you use rsync over ssh. This allows a secure remote connection. Now let us see some examples of rsync.

Rsync command common options
  • -- Delete: Delete files that don't exist on sender (system)
  • -V: Verbose (try-VvFor more detailed information)
  • -E "ssh options": Specify the ssh as remote shell
  • -: Archive mode
  • -R: Recurse into directories
  • -Z: Compress file data
Task: Copy file from a local computer to a remote server

Copy file from/www/backup.tar.gz to a remote server called openbsd. nixcraft. in

$ Rsync-v-e ssh/www/backup.tar.gz jerry@openbsd.nixcraft.in :~

Output:

Password: sent 19099 bytes received 36 bytes 1093.43 bytes/sec total size is 19014 speedup is 0.99

Please note that symbol~Indicate the users home directory (/home/jerry ).

Task: Copy file from a remote server to a local computer

Copy file/home/jerry/webroot.txt from a remote server openbsd. nixcraft. in to a local computer/tmp directory:

$ Rsync-v-e ssh jerry@openbsd.nixcraft.in :~ /Webroot.txt/tmp

Password

Task: Synchronize a local directory with a remote directory $ rsync-r-a-v-e "ssh-l jerry" -- delete openbsd. nixcraft. in:/webroot // local/webrootTask: synchronize a remote directory with a local directory $ rsync-r-a-v-e "ssh-l jerry" -- delete/local/webroot openbsd. nixcraft. in:/webrootTask: Synchronize a local directory with a remote rsync server $ rsync-r-a-v -- delete rsync: // rsync. nixcraft. in/cvs/home/cvsTask: Mirror a directory between my "old" and "new" web server/ftp

You can mirror a directory between my "old" (my.old.server.com) and "new" web server with the command (assuming that ssh keys are set for password less authentication)

$ Rsync-zavrR -- delete -- links -- rsh = "ssh-l vivek" my.old.server.com:/home/lighttpd

========================================================== ==============

When you need to copy files on the server to another machine, you can use rsync to synchronize files.

I. Server Configuration:
# Yum-y install xinetd

# Vi/etc/xinetd. d/rsync
Run the following code:

Copy codeThe Code is as follows: service rsync
{
Disable = yes
Socket_type = stream
Wait = no
User = root
Server =/usr/bin/rsync
Server_args =-daemon
Log_on_failure + = USERID
}

InDisable = yesChangeDisable = no

Then start xinetd

Copy codeThe Code is as follows: #/etc/init. d/xinetd start

Note: If the server is installed with a firewall, remember to open the port. The default port is 873.

Copy codeThe Code is as follows: # telnet 127.0.0.1 873

Trying 127.0.0.1...
Telnet: connect to address 127.0.0.1: Connection refused
# Iptables-a input-s 192.168.0.0/255.255.255.0-p tcp-m tcp -- dport 873-j ACCEPT
# Iptables-a input-p tcp-m tcp -- dport 873-j DROP

# Vi/etc/rsyncd. conf

Copy codeThe Code is as follows: [backup]
Path =/www
Auth users = admin
Uid = root
Gid = root
Secrets file =/etc/rsyncd. secrets
Read only = no

[Server code]
Path = backup file path
Auth users = authorized account
Uid = uid at execution time
Gid = gid at execution time
Secrets file = Password file Location
Read only = read-only or not

# Vi/etc/rsyncd. secrets

Copy codeThe Code is as follows: admin: 1234 # Username: Password Authentication

Give the file the correct permissions
# Chown root: root/etc/rsyncd. secrets
# Chmod 600/etc/rsyncd. secrets

2. client-side Synchronization
By default, the client seems to have installed rsync. If not, install the following:
# Yum-y install rsync

Perform asynchronous synchronization:

/Usr/bin/rsync-avz-progress admin@192.168.1.105: backup/www

Synchronization command description:

1. Display directory content

Command
--
A) rsync
B) rsync-r
C) rsync jack@192.168.0.1 ::
D) rsync ssh_user@192.168.0.1:

Command description
---
A) display directory content (level 1)
B) recursively display directory content
C) display the remote host directory content
* Note 1: Port mode, based on rsync User Authentication
* Note 2: The directory on rsync server must have the xx7 permission.
D) view the remote host directory
* Note 1: In remote shell mode, authentication based on the identity of local users connected through ssh
* Note 2: Only one colon (:) is used here, and the user name is the ssh user of the remote host, and the password is also the password of the ssh user.
* Note 3: Use "to list information about the folder itself. To list folder content, use "/".

Parameter description
---
-R performs recursive operations on directories.

2. synchronization between local directories

Command
--
A) rsync-av-progress/*** note (/)***
B) rsync-av-progress
C) rsync-avu-progress-delete/
D) rsync-av-progress-temp-dir =/tmp/

Command description
---
A) synchronize all files under the src-dir directory to the dst-dir directory.
B) synchronize all files under the src-dir directory to the dst-dir/src-dir directory.
C) Update the src-dir directory content to the dst-dir directory for differential updates. If there is an increase/update, add or replace it. If there is a decrease, delete it.
D) More-temp-dir =/tmp than a), that is, specify/tmp as a temporary swap zone, so as to avoid file synchronization errors caused by insufficient space in the target directory.

Parameter description
---
-A is equivalent to the-rlptgoD set.
-U is equivalent to-update. It is not updated when the target file is newer than the source file.
-V: Display synchronized files
-Progress displays the percentage progress and transmission rate during file synchronization.
-Delete: delete files in the target directory that are more than the source directory.

3 synchronization between remote hosts
Command
--
A) rsync-avz-progress jack@192.168.0.1 ::/
B) rsync-avz-progress jack@192.168.0.1:/-password-file =/home/jack/rsync. jack
C) rsync-avuz-progress-delete jack@192.168.0.1:/-password-file =/home/jack/rsync. jack
D) rsync-avz-progress jack@192.168.0.1 ::/

Command description
---
A) synchronize the contents of the local directory to the directory of the remote host 192.168.0.1. jack is the rsync database user (see 3./etc/rsync. secrets)
B) synchronize non-interactive login files by automatically reading user passwords
C) more than B)-u and-delete
D) synchronize the remote host content to the local directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.