Article Title: Rsync introduction to file processing commands. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
After Rsync completes data backup, this operation will be automatically terminated. For this purpose, it is best to add a "-a" option (for files) and "-e" option on the basis of the preceding command to specify the remote shell program to ensure security. In this case, the remote shell uses an encryption protocol, such as ssh, so that the remote shell can use the-e ssh format.
In this case, the above Rsync command is protected by the ssh encryption protocol. The specific form is as follows:
Rsync-a-e ssh localdir host: remotedir
If you want to know what happens during the entire file copy process, you can use the-v and-progress options. -V indicates the detailed operation process. By default, rsync simply Copies files, does not print anything, and does not disturb users as much as possible. It simply and quickly completes the task. If this option is used only once, the-v option will report all the copied files and generate the total amount at the end. If you use the-v option twice, that is, to use-vv in the command, rsync will not only report all the copied files, but also those files that do not need to be copied, and provide more detailed information at the end. -The progress option task mainly displays the current copy progress, including the current file size, completed percentage, current transmission speed, remaining time estimation, and so on. If you want to write a command using the reoption mode and the ssh tunnel protocol, and require a progress indicator, you can use the following form:
Rsync-avv-e ssh-progress localdir host: remotedir
If the transmission is interrupted during the file copy process, Rsync uses the default operation to undo the previous operation, that is, to delete some copied files from the target machine. If you do not need to re-copy all files during the next copy, you can use the-partial option to prevent rsync from deleting the copied part during the transmission interruption. If you want to use both the-partial and-progress options, you can use the-P option, which is a more convenient option provided by rsync and can replace the two. Therefore, if you want to copy files in the option-complex mode, disable the delete option, and require progress indicator and ssh tunnel protocol protection, you can use the following command:
Rsync-avvP-e ssh localdir host: remotedir
If you want the system to handle the task as scheduled, you can simply add the Rsync command to the background daemon task. For example, to add the rsync command to the/etc/crontab file, use the following method:
30 4 *** user rsync-aP-e ssh localdir host: remotedir
The first five items in the background job task are used to define when a task is scheduled. The sixth item tells the background daemon which user will run the task. Replace the "user" character string in the following example with the actual user account that runs the task. In this example, the background daemon is set to run once every morning. The meanings of the first five fields are seconds, hours, a day in the month, a month in the year, and a day in the week. The time starts with 0, so the second is 0-59, and the hour is 0-23. The following two fields: one day in the month and one month in the year, are 1-31 and 1-12. The last field, one day of the week, is 0-7. Both 0 and 7 represent Sunday. The actual background daemon configuration files are more complex, but these are the basic operations for creating background programs during data backup using rsync. To learn more about how to create a background daemon, Run man cron, man crontab, and man 5 crontab. To centrally manage the data backup backend daemon, you can create the following backend daemon on the backup server:
30 4 *** user rsync-aP-e ssh host: remotedir localdir
After setting as described above, Rsync will collect file information from the directory (remotedir) on a specific remote host, and copy these files to your specified local (localdir) directory.