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.