====== 与服务器文件同步 ====== ==== rsync 监控目录并同步 ==== [[https://www.ruanyifeng.com/blog/2020/08/rsync.html|rsync 用法教程]] :-) [[https://segmentfault.com/a/1190000018024251|跨平台的fswatch+rsync同步备份]] / [[https://shadowdragons.github.io/2017/02/02/mac-rsync-fswatch/|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 ubuntu@192.168.0.136:/home/ubuntu/apis # scp -P file_name user@ip:/dir_name ==== 使用 expect 交互命令 ==== [[http://xstarcd.github.io/wiki/shell/expect_handbook.html|expect 中文教程]] / [[http://xstarcd.github.io/wiki/shell/expect.html|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 @:/destination_path set pass "*******" expect { password: {send "$pass\r"; exp_continue} } 然后执行脚本文件 ''expect path_to/deploy.exp'' 如果希望执行以后继续留在进程内,比如 “su -” 更换root用户,需要将 exp_continue 换成 ''%%interact%%'' 。 {{tag>shell vps 文件系统}}