linux查看端口占用_Linux rsync同步文件脚本分享

时间:2020-09-22  来源:php安装  阅读:

使用rsync可以实现文件备份同步,现实的一个使用场景是,在后台上传的模板文件,需要同步到另一台服务器,通过别的域名地址访问,这就需要把后台上传的文件自动同步到对外可访问的服务器。

记录一个rsync同步文件的sh脚本,作为例子:

 代码如下 #!/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
do
        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

再来一个:

 代码如下

#!/bin/bash
server="t16b21 c16b181"
for i in $server
do
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

在PHP中使用exec函数可以执行sh脚本文件,实现文件同步,如下:

 代码如下

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

这样当在后台上传文件完成后,即可使用exec执行同步脚本把文件同步到另一台服务器。

当然rsync还有更多的使用场景。

tar exclude排除某个目录

记录一下tar压缩命令排除某个目录语法:

Vim

 代码如下

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

以上命令是打包当前目录下除了两个exlude注明的目录。

压缩结束有一句提示:tar: .: file changed as we read it,不过压缩包解压出来没发现遗漏。先无视。

linux查看端口占用_Linux rsync同步文件脚本分享

http://m.bbyears.com/jiaocheng/100249.html

推荐访问:linux安装mysql linux查看磁盘空间 linux学习
相关阅读 猜你喜欢
本类排行 本类最新