Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Rsync in Shell

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Rsync is used in Shell. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The operation terminates on its own after the backup of Rsync usage data is completed. For this, * adds a "- a" option (for files) and "- e" option to the above command to specify the use of a remote shell program to ensure security. At this point, the remote shell will use an encryption protocol, such as ssh, so that the remote shell can use the-e ssh format.

In this way, the above Rsync commands are protected by the ssh encryption protocol, as follows:

Rsync-a-e ssh localdir host:remotedir

If you want to know what happened throughout the file copy process, you can use the-v and-progress options. The-v option indicates that the detailed operation is printed. The default operation of rsync is to simply copy files, do not print anything, try not to disturb the user, and simply and quickly complete the task. If used only once, the-v option will report all copied files and give the total amount in *. If you use the-v option twice, that is, if you use-vv in the command, rsync will report not only all files that have been copied, but also those that do not need to be copied, and give more details in *. The task of the-progress option is to display the current copy progress, including the current file size, percentage completed, current transfer speed, estimated remaining time, and so on. If you want to write a command that uses multiple option mode and ssh tunneling protocol, and requires a progress indicator, it can be in the following form:

Rsync-avv-e ssh-progress localdir host:remotedir

If the transfer is interrupted while copying the file, the default action used by Rsync is to undo the pre-action, that is, to delete some of the copied files from the target machine. If you want to continue the file on the next copy and do not need to re-copy all the files, you can use the-partial option to prevent rsync from deleting the copied parts if the transfer is interrupted. 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 instead of both. Therefore, if you want to use the file copy in multiple option mode and turn off the delete option, while requiring the protection of a progress indicator and ssh tunneling protocol, you can use the following command:

Rsync-avvP-e ssh localdir host:remotedir

If you want the system to handle itself according to the scheduled schedule, you can simply add the Rsync usage command to the background daemon task. For example, to add a rsync command to the / etc/crontab file, the method is as follows:

30 4 * user rsync-aP-e ssh localdir host:remotedir

The first five items of the background job task are used to define when a task is scheduled, and the sixth tells the background daemon which user will run the task. You can replace the "user" string in the following example with the actual user account that will run the task. The daemon in the example is set to run at 4:30 every morning. The first five fields mean seconds, hours, a day in a month, a month in a year, and the day of the week. Time begins with 0, so seconds are 0-59 and hours are 0-23. The next two fields, a day in a month and a month in a year, are 1-31 and 1-12. * A field in which the day of the week is 0-7, and both 0 and 7 represent Sunday. The actual background daemon configuration file is more complex than this, but these are the basic operations of creating a daemon when backing up data with rsync. If you want to know more about creating a daemon, you can get it by launching the commands man cron,man crontab and man 5 crontab. If you want to centrally manage the data backup background daemon, you can create the following background daemon on the backup server:

30 4 * user rsync-aP-e ssh host:remotedir localdir

When set up as described above, Rsync usage will collect file information from a directory (remotedir) on a specific remote host and copy the files to the local (localdir) directory you specify.

Thank you for reading! This is the end of the article on "how to use Rsync in Shell". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report