In daily operations, we often use rsync as a synchronization artifact. Sometimes when synchronizing two directories, it is required to delete files in the target directory that are more than the source directory, in which case the--delete parameter of rsync can be used to implement this requirement.Like what:Synchroniz
Recently, when processing planning resource files, you need to synchronize all the files in directory A to the files in directory B and delete all the unnecessary files in directory B. Therefore, you can use the -- delete parameter of rsync to implement the function.Example:// Create two test Directories$ Mkdir {Dira, dirb}// Create the corresponding files in the
Format:Rsync -- delete-before-a-H-v -- progress -- statsOption:-- Delete-before: the receiver is deleted before transmission.-Progress displays the transmission process during transmission-A indicates that files are transmitted recursively and all file attributes are maintained.-R recursively processes subdirectories.-H: Keep hard-connected files-V detailed output mode
Example:/Home/aniya/is an empty folder
Format: rsync -- delete-before-a-H-v -- progress -- stats options: -- delete-before: the receiver deletes the object before transmission.-progress displays the transmission process during transmission.-a Archive mode indicates that the object is transmitted recursively and all objects are kept...
Format:Rsync -- delete
Rsync is a sync tool I just used it to do data synchronization operation did not want to do file deletion operation, but today saw an article can implement file deletion operation, below we take a look.
Use rsync to synchronize an empty directory. For the million-level file directory is the basic second Delete, enter the OK.
The steps are as follows:
1. Create
Yesterday, we encountered a situation where we wanted to delete a large number of files in Linux. We needed to delete several 100,000 files. This is the log written by the previous program, which is growing fast and useless. At this time, the common delete command rm-fr * is not easy to use, because it takes too long to wait. Therefore, we must take some extraord
The usual Delete command RM-FR * is not useful, because the time to wait is too long. So we have to take some very good measures.We can use rsync to quickly delete large numbers of files. 1. Install rsync First:
yum install rsync
2. Create an empty folder:
Yesterday encountered the need to delete a large amount of files under Linux, you need to delete hundreds of thousands of files. This is a log of the previous program, growing fast and useless. This time, we often use the delete command RM-FR * is not useful, because the time to wait too long. So we have to take some very good measures. We can use
a few of the frequently used parameters here:-v,-a,-z, the specific instructions for these parameters are described in this article "Slime:" to "rsync command parameters in detail." -V,--verbose verbose mode output. -A,--archive archive mode, which means that files are transferred recursively and that all file attributes remain intact. -Z,--compress compresses the files that are backed up when they are transferred. --
exceed the limit will be notified and then try again.
0 (no restrictions)
Lock file
Specifies the lock file that supports the max connections parameter.
/Var/run/rsyncd. lock
List
Specify whether the module should be listed when the customer requests to list available modules. If this option is set to false, you can create a hidden module.
True
Read only
Specifies whether the client is allowed to upload files. If the value is true, upload is not allo
indicates that you want to use a recursive method for synchronization and maintain consistency in all aspects as much as possible.
However,-a cannot synchronize hard links. If you have such requirements, add the-H option.
[-Delete option,-delete-excluded option, and-delete-after option]
The three options are related to "del
1.RSYNC: Remote sync, support local replication, or synchronize with other SSH and RSYNC hosts.Rsync remote synchronization and CP, SCP function basically consistent, the other two is to copy the source files, if there is new data added, using CP, SCP to the source file all the content is copied, and Rsync is on the basis of the source files only update the newly
.
Rsync can also be used to delete files and directories, which is equivalent to the rm command.
An rsync is equivalent to scp, cp, and rm, but better than each of them.Rsync features
1. Supports copying special files, such as linked files and devices.
2. You can exclude the synchronization of specified files or directories, which is equivalent to the exclusion f
.
Rsync can also be used to delete files and directories, which is equivalent to the rm command.
An rsync is equivalent to scp, cp, and rm, but better than each of them.Rsync features
1. Supports copying special files, such as linked files and devices.
2. You can exclude the synchronization of specified files or directories, which is equivalent to the exclusion f
1. Using Ssh+rsyncYou only need to open the SSH service on the server side and start the rsync service in xinetd to useA. Incremental synchronizationrsync-av/src-dir/. [email protected]:/dest-dir/.B. Mirroring synchronizationRsync-av--delete/src-dir/. [email protected]:/dest-dir/.Features: Simple configuration, no need to configure rsyncd.conf profile, but requires user authentication during synchronization
Rsync synchronization after the directory structure is consistent, ${inotify}/ Inotifywait-mrq--format '%xe%w%f '-e modify,create,delete,attrib,close_write,move./| While read file# monitors the list of file paths that have changed loop do ino_event=$ (echo $file | awk ' {print $} ') # assigns the inotify output cut to the event type portion to Ino_ EVENT ino_file=$ (echo $file | awk ' {print $} ') # Assign
. Support anonymous transmission, in order to facilitate the site mirror image, etc.;6. Encrypt transmission data, ensure the security of data;Rsync-av/etc/passwd/tmp/0.txtRsync-av/tmp/0.txt 192.168.1.101:/tmp/1.txtFormat:rsync [OPTION] ... SRC (source directory) DEST (destination directory)rsync [OPTION] ... SRC [[Email protected]]host:destrsync [OPTION] ... [[Email Protected]]host:src DESTrsync [OPTION] .
will reduce performance again.The Daemon
Like many other daemon, a daemon sub-process is fork for each connection. At startup, it will parse the rsyncd. conf file to determine which modules exist and set global options.When a defined module receives a connection, daemon will fork a sub-process to process the connection. Then the sub-process reads the rsyncd. conf file and sets the option of the requested module. This may cause chroot to the module path and
Rsync + inotify for data synchronization and FAQs
Rsync: Remote Sync is a data image backup tool for Unix-like systems. Rsync can be used to back up data with low real-time requirements. For example, you can use the specified backup file server to back up data to the specified remote server and regularly perform data mirroring on the local disk.
Inotify: inotify
file must be 600, otherwise the client will not be able to connect to the server. Strict modes this option specifies whether to monitor the permissions of the password file. if this option is set to true, the password file can only be accessed by users who run The rsync server identity, other users cannot access this file. The default value is true. Hosts allow this option specifies which IP addresses are allowed to connect to the module. The custome
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.