跨平台的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 -r ./libs ./resources ./dist ./*.js ./*.json [email protected]:/home/ubuntu/apis # scp -P <port> file_name user@ip:/dir_name
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
。