Always use rsync over SSH
Since Rsync does not provide the No. Transferring data it is recommended that to use rsync over SSH. This allows a secure remote connection. Now let us-some examples of rsync.
rsync Command common options
- --delete : Delete files that don ' t exist on sender (System)
- - v : Verbose (try -vv for more detailed information)
- - E "ssh Options" : Specify the SSH as remote shell
- -A: 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-bytes 1093.43 bytes/sec total
size are 19014 speedup is 0.99
Please note this 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 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/webroot
Task:synchronize a remote directory with a local directory
$ rsync-r-a-v-E "ssh-l Jerry"--delete/local/webroot Openbsd.nixcraft.in:/webroot
Task:synchronize a local directory with a remote rsync server
$ rsync-r-a-v--delete Rsync://rsync.nixcraft.in/cvs/home/cvs
Task:mirror a directory between my ' old ' and ' new ' web server/ftp
You can mirror a directory between I "old" (my.old.server.com) and "new" Web server with the command (assuming that SSH K Eys are set for password less authentication)
$ RSYNC-ZAVRR--delete--links--rsh= "ssh-l Vivek" my.old.server.com:/home/lighttpd/home/lighttpd
===================================================
When you need to copy files from the server to another machine, you can use rsync to sync the files.
First, server-side configuration:
# yum-y Install xinetd
# Vi/etc/xinetd.d/rsync
The following code
Copy Code code as follows:
Service rsync
{
Disable = yes
Socket_type = Stream
wait = no
user = root
Server =/usr/bin/rsync
Server_args =–daemon
Log_on_failure + + USERID
}
Disable = yes change to
disable = no
and start xinetd.
Copy Code code as follows:
#/etc/init.d/xinetd Start
Note: If the server is equipped with a firewall, remember to open the port, the default port is 873
Copy Code code 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 Code code 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 accounts
UID = uid at execution
GID = gid at execution
Secrets file = Password files location
Read Only = is reading only
# vi/etc/rsyncd.secrets
Copy Code code as follows:
admin:1234 # Username: password
Correct permissions to the file
# chown Root:root/etc/rsyncd.secrets
# chmod 600/etc/rsyncd.secrets
Second, the client side of the synchronization
The client defaults as if it had been installed in rsync, without the words installed:
# yum-y Install rsync
To perform an asynchronous synchronization operation:
/usr/bin/rsync-avz–progress admin@192.168.1.105::backup/www
Sync Command Description:
1 Displaying directory Contents
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 contents (first level)
b) recursive display of directory content
c) Displaying the contents of the remote host directory
* NOTE 1: Port mode, authentication based on rsync user
* Note the directory on the 2:rsync server must have XX7 permissions.
d) View the contents of the remote host directory
* Note 1:remote shell mode, authentication based on system local user via SSH connection
* NOTE 2: This only uses a colon (:), while the user name is the remote host SSH user, the password is the SSH user's corresponding password.
* Note 3: Use "" To list information about the folder itself. To list the contents of a folder, you should use "/".
Parameter description
———
-R recursive operation of the directory
2 Sync between local directories
Command
——
a) rsync-av–progress/* * * ATTENTION (/) * * *
b) rsync-av–progress
c) Rsync-avu–progress–delete/
D) rsync-av–progress–temp-dir=/tmp/
Command description
———
A) Synchronize all files in the Src-dir directory to the Dst-dir directory
b Synchronize all files in the Src-dir directory to the Dst-dir/src-dir directory
c) The content of the Src-dir directory to the Dst-dir directory for differential updates, there are additions/updates to add replacement, there is a reduction in the deletion
D) More than a –temp-dir=/tmp, that is, specify/tmp as a temporary swap area, so as to avoid errors due to insufficient target directory space caused by the inability to sync files.
Parameter description
———
-A is equivalent to the-rlptgod set
-U is equivalent to –update and is not updated when the target file is newer than the source file
-V Display synchronized files
–progress percentage progress, transfer rate when file synchronization is displayed
–delete Delete files in the destination directory 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 to synchronize the contents of the local directory to the remote host 192.168.0.1 directory, Jack is an rsync database user (see 3/etc/rsync.secrets)
(b) Synchronization of non-interactive logon files by automatically reading user passwords
c) more than B-U and –delete
d Synchronize remote host content to local directory