RSYNC software introduction: rsync is a data image backup tool in unix-like systems. It can be seen from the software name-remote sync.
I. Use rsync to start rsyncserver
Two Methods for RSYNC server startup
1. Start the rsync server to start independently)
#/Usr/bin/rsync-daemon
2. Start the rsync server with the xinetd superprocess)
#/Etc/rc. d/init. d/xinetdreload
Ii. Add rc. local to rsync
In various operating systems, rc files are stored in different locations and can be modified so that rsync-daemon can be loaded during system startup.
# Vi/etc/rc. local
Add/usr/local/rsync-daemon
Check rsync
# Netstat-a | greprsync
Tcp000.0.0.0: 8730.0.0.0: * LISTEN
Iii. rsync configuration rsyncclient
1. Set the password
# Vi/etc/rsync. pas
111111
Modify permissions
# Cd/etc
# Chownroot. rootrsync. pas
# Chmod600rsync. pas
2. Connect the client to the SERVER
Retrieving files from the SERVER
/Usr/bin/rsync-vzrtopg--progress--deletehening@192.168.0.217: backup/home/backup -- password-file =/etc/rsync. pas
Upload files to the SERVER
/Usr/bin/rsync-vzrtopg -- progress -- password-file =/root/rsync. pas/home/backuphening@192.168.0.217: backup
This command backs up all files in the local/home/backup Directory and subdirectories to the backup directory set by the backup module of RSYNCSERVER172.20.0.6.
Note that if the path ends with "/", it indicates backing up the stuff in the directory, but it does not create this directory. If it does not contain "/", it is created.
RSYNC usage:
Rsync [OPTION]... [USER @] HOST: SRC [DEST] # Back Up Files from RSYNCSERVER to Local Machine
Rsync [OPTION]... SRC [SRC]... [USER @] HOST: DEST # Back Up Files from local machines to RSYNCSERVER
3. Automatic Operation
1) vi/usr/local/rsync/time. sh // create a script file
Copy the following content
#! /Bin/bash
/Usr/bin/rsync-vzrtopg--progress--deletehening@192.168.0.217: backup/home/backup -- password-file =/etc/rsync. pass
2) Add crontab-e to 55 */usr/local/rsync/time. sh // run the time. sh script file every 55 minutes.
4. iptables
Iptables-AINPUT-ptcp-s! 11.22.33.44 -- dport873-jDROP
In this case, only the clientIP 11.22.33.44 can enter this rsyncserver.
Command Introduction:-rvlHpogDtS
Rsync Command Parameters
-V indicates verbose details
-Z indicates Compression
-R indicates recursive Recursion
-T indicates the creation time of the original file.
-O indicates to keep the original file owner
-P indicates the parameter for retaining the original file.
-G indicates the group to which the original file belongs.
-A archive Mode
-P indicates the option function that replaces-partial and-progress.
-Essh establishes an encrypted connection.
-- Partial: prevents rsync from deleting the copied part during transmission interruption (if the transmission is interrupted during file copy, rsync's default operation is to cancel the previous operation, that is, some copied files are deleted from the target machine .)
-- Progress indicates that the detailed progress is displayed.
-- Delete: if the server deletes the file, the client also deletes the file to ensure true consistency.
-- Exclude does not include the/ins directory
-- Size-only: the difference between the two folders is that there are some new files in the source folder, and there are no files with duplicate names and modified names, this type of file may be omitted because the content is modified to the same size. This parameter can greatly improve synchronization efficiency because it does not need to check whether the content of files with the same name is the same.
-- Password-file: Specifies the password file, which contains the password of the user specified by the server.
In this way, you can use the password in the script without entering the verification password interactively. Note that the permission attribute of this password file must be set to only the owner-readable.
Hening@192.168.0.217: backup
Hening refers to the user specified for authentication on the server.
192.168.0.217 indicates the ip address of the server.
: Backup indicates the name of the module to be synchronized on the server;
/Home/quack/backup/$ DATE indicates the directory address of the synchronized file stored in the local machine.
/Var/log/rsync. $ DATE is the directory address of the Synchronized log files stored in the local machine.
Note:
If you do not put/, the directory name also contains mirror. If you put/, There is only mirror in the directory.