Linux rsync sync File script sharing

Source: Internet
Author: User
Tags rsync

Use rsync can achieve file backup synchronization, a realistic use of the scene is, in the background upload template files, need to sync to another server, through other domain name address access, this need to upload files in the background automatically synchronized to the external access to the server.

Log the sh script for an rsync sync file as an example:

The code is as follows Copy Code
#!/bin/bash
Rsync-avz--password-file=/etc/rsync.msg.key/usr/local/zeus/htdocs/act.example.com Vip@t11.example.net::act.vip1 --port=873
Rsync-avz--password-file=/etc/rsync.msg.key/usr/local/zeus/htdocs/act.example.com Vip@t12.example.net::act.vip1 --port=873
servers= ' T16b21 c16b181 '
Src= '/usr/local/zeus/htdocs/example.com '
For server in $servers
Todo
Dst= "Vip@${server}.sandai.net::act.vip1"
Rsync-avz--password-file=/etc/rsync.msg.key $src $dst--port=8873
# rsync-avz-e ssh/usr/local/zeus/htdocs/act.example.com root@ $server. sandai.net:/usr/local/zeus/htdocs/
Done

One more:

The code is as follows Copy Code

#!/bin/bash
server= "T16b21 c16b181"
For I in $server
Todo
rsync-avz/usr/local/zeus/htdocs/images.client.example.com/vip@ $i. example.net::images.client/--port=8873-- Password-file=/etc/client.secret
rsync-avz/usr/local/zeus/htdocs/images.client.example.com/vip@ $i. example.net::images.client/--port=873-- Password-file=/etc/client.secret
Done

Using the EXEC function in PHP, you can execute the SH script file and synchronize the files as follows:

The code is as follows Copy Code

EXEC ("/usr/local/bin/rsync_act_vip_xunlei_com_to_twin14419.sh");

This allows you to synchronize files to another server using the Exec Execution synchronization script when the upload file is completed in the background.

Of course, Rsync also has more use scenarios.

Tar exclude exclude a directory

Record the TAR compression command excludes a directory syntax:

Vim

The code is as follows Copy Code

TAR-ZCVF daili.tar.gz--exclude=./inc/log--exclude=./api/tmp./

The above command is packed in the current directory except for two exlude annotated directories.

Compression end there is a hint: tar:.: File changed as we read it, but the compression package was uncompressed and found no omissions. Ignore it first.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.