与服务器文件同步

rsync 监控目录并同步

rsync 用法教程 :-)

跨平台的fswatch+rsync同步备份 / mac使用rsync+fswatch实现目录文件实时同步

选择一个网络驱动器,并右键在 Terminal 中打开,就可以使用命令。

rsync -avzP --delete --exclude='node_modules' /Users/mai/Stock ./Stock
# 一定要加“./Stock”,单单一个“.” 会覆盖整个根目录

大的文件夹先使用Tar会更好一些

tar -zcvf aliyun.tar.gz --exclude "node_modules" /Users/mai/projects/aliyun
# 如果不想保护目录,需要进入到文件夹内进行压缩
tar -xzf aliyun.tar.gz

增量备份

$ rsync -a --delete --link-dest /compare/path /source/path /target/path

上面命令中,–link-dest参数指定基准目录/compare/path,然后源目录/source/path跟基准目录进行比较,找出变动的文件,将它们拷贝到目标目录/target/path。

scp 脚本命令


scp -r ./libs ./resources ./dist ./*.js ./*.json [email protected]:/home/ubuntu/apis

# scp -P <port> file_name user@ip:/dir_name

使用 expect 交互命令

expect 中文教程 / expect 自动交互脚本

apt-get install expect -y

脚本 “deploy.exp” 文件

#!/usr/bin/expect
spawn scp -r ./libs ./resources ./dist index.js app.js jobs.js package.json <username>@<host_ip|name>:/destination_path
set pass "*******"
expect {
password: {send "$pass\r"; exp_continue}
}

然后执行脚本文件 expect path_to/deploy.exp

如果希望执行以后继续留在进程内,比如 “su -” 更换root用户,需要将 exp_continue 换成 interact

it/server/file_sync.txt · 最后更改: 2022-08-29 18:45 由 goldentianya
回到顶部
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0