OS X / LINUX使用RSYNC拷贝远程服务器文件到本地

3 篇文章 0 订阅
2 篇文章 0 订阅

这篇博客翻译自http://biodegradablegeek.com/category/linux/

下边部分的代码使用Rsync从远程服务器拷贝文件到本地机器,从而使本地和远程服务器的文件保持同步。这是一个备份web服务器重要目录到外部硬盘或者其他什么地方的有用技巧。

The following is used to copy files from a remote server to your local machine using Rsync to keep both synchronized. This is useful for things like backing up important directories on your web server to your external hard drive or elsewhere.

Rsync可以在本地和远程服务器之间文件增量备份,也就是说只是同步你的远程服务器上更新了的文件到本地服务器。

Rsync can incrementally synchronize files between two locations whether local or remote. This means only the updated files on your remote server are updated on your local machine.

从接下来的部分我假设你和我一样也是使用OS X, 但是这个脚本应该也能在Linux工作。 首先需要打开一个控制台(就是那个令人讨厌的黑框框),在命令行的提示符下,输入一下的代码:

From here on in I assume you’re using OS X but this should work on Linux as well. Press CMD+Space to open a Terminal (I use TotalTerminal.) At the command prompt, just use the following:
#!/bin/sh
rsync -a -e "ssh" --rsync-path="sudo rsync -vau " remoteusername@remote.host.com:/home .
rsync -a -e "ssh" --rsync-path="sudo rsync -vau " remoteusername@remote.host.com:/var .
rsync -a -e "ssh" --rsync-path="sudo rsync -vau " remoteusername@remote.host.com:/etc .

这个脚本执行的结果是拷贝你远程服务器的/home,/var, /etc目录到当前目录。

This will copy /home, /var, and /etc from your remote machine to the current directory.

可以把上述的代码拷贝到一个文件,可以命名成rsyncRemote.sh, 并使用下述的命令执行之可以实现相同的效果

# should under same directory with rsyncRemote.sh
chmod a+x rsyncRemote.sh
./rsyncRemote.sh
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值