I absolutely love the Keep Remote Directory Up-to-date feature in Winscp. Unfortunately, I can't find anything as simple to use in OS X or Linux. I know the same thing can theoretically be accomplished using changedfiles or rsync, but I've always found the tutorials for both tools to be lacking and/or contradictory.
我非常喜欢Winscp中的Keep Remote Directory update特性。不幸的是,我在OS X或Linux中找不到任何简单的东西。我知道使用changedfiles或rsync也可以完成相同的任务,但我总是发现这两种工具的教程都缺乏和/或相互矛盾。
I basically just need a tool that works in OSX or Linux and keeps a remote directory in sync (mirrored) with a local directory while I make changes to the local directory.
我基本上只需要一个工具,它可以在OSX或Linux中工作,并将远程目录与本地目录同步(镜像),同时对本地目录进行更改。
Update
更新
Looking through the solutions, I see a couple which solve the general problem of keeping a remote directory in sync with a local directory manually. I know that I can set a cron task to run rsync every minute, and this should be fairly close to real time.
通过查看这些解决方案,我看到了两个解决方案,它们解决了手动将远程目录与本地目录保持同步的一般问题。我知道我可以设置一个cron任务来每分钟运行rsync,这应该是相当接近实时的。
This is not the exact solution I was looking for as winscp does this and more: it detects file changes in a directory (while I work on them) and then automatically pushes the changes to the remote server. I know this is not the best solution (no code repository), but it allows me to very quickly test code on a server while I develop it. Does anyone know how to combine rsync with any other commands to get this functionality?
这并不是我在winscp中寻找的正确解决方案:它检测目录中的文件更改(当我处理它们时),然后自动将更改推送到远程服务器。我知道这不是最好的解决方案(没有代码存储库),但是它允许我在开发服务器时非常快速地测试代码。有没有人知道如何将rsync与其他命令结合使用以获得这个功能?
15 个解决方案
#1
16
How "real-time" do you want the syncing? I would still lean toward rsync since you know it is going to be fully supported on both platforms (Windows, too, with cygwin) and you can run it via a cron job. I have a super-simple bash file that I run on my system (this does not remove old files):
如何“实时”同步?我仍然倾向于使用rsync,因为您知道它将在两个平台上(Windows也支持cygwin),您可以通过cron作业运行它。我有一个超级简单的bash文件,我在我的系统上运行(这不会删除旧文件):
#!/bin/sh
rsync -avrz --progress --exclude-from .rsync_exclude_remote . remote_login@remote_computer:remote_dir
# options
# -a archive
# -v verbose
# -r recursive
# -z compress
Your best bet is to set it up and try it out. The -n (--dry-run)
option is your friend!
你最好的办法就是把它设置好,然后试一试。-n (- run)选项是你的朋友!
Keep in mind that rsync (at least in cygwin) does not support unicode file names (as of 16 Aug 2008).
请记住,rsync(至少在cygwin中)不支持unicode文件名(截至2008年8月16日)。
#2
39
lsyncd seems to be the perfect solution. it combines inotify (kernel builtin function which watches for file changes in a directory trees) and rsync (cross platform file-syncing-tool).
lsyncd似乎是完美的解决方案。它结合了inotify(内核构建函数,监视目录树中的文件更改)和rsync(跨平台文件同步工具)。
lsyncd -rsyncssh /home remotehost.org backup-home/
Quote from github:
从github报价:
Lsyncd watches a local directory trees event monitor interface (inotify or fsevents). It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronize the changes. By default this is rsync. Lsyncd is thus a light-weight live mirror solution that is comparatively easy to install not requiring new filesystems or blockdevices and does not hamper local filesystem performance.
Lsyncd监视本地目录树事件监视器接口(inotify或fsevents)。它聚合并组合事件几秒钟,然后生成一个(或多个)进程来同步更改。默认情况下这是rsync。因此,Lsyncd是一个轻量级的活动镜像解决方案,相对容易安装,不需要新的文件系统或块设备,并且不会影响本地文件系统的性能。
#3
8
What you want to do for linux remote access is use 'sshfs' - the SSH File System.
对于linux远程访问,您需要做的是使用“sshfs”——SSH文件系统。
# sshfs username@host:path/to/directory local_dir
Then treat it like an network mount, which it is...
然后把它当作一个网络挂载,它是…
A bit more detail, like how to set it up so you can do this as a regular user, on my blog
更多的细节,比如如何设置它,以便作为一个普通用户,你可以在我的博客上这样做
If you want the asynchronous behavior of winSCP, you'll want to use rsync combined with something that executes it periodically. The cron solution above works, but may be overkill for the winscp use case.
如果您想要winSCP的异步行为,您将希望使用rsync和一些定期执行的东西结合使用。上面的cron解决方案是有效的,但是对于winscp用例来说可能有些过头了。
The following command will execute rsync every 5 seconds to push content to the remote host. You can adjust the sleep time as needed to reduce server load.
下面的命令将每5秒执行一次rsync,将内容推送到远程主机。您可以根据需要调整睡眠时间,以减少服务器负载。
# while true; do rsync -avrz localdir user@host:path; sleep 5; done
If you have a very large directory structure and need to reduce the overhead of the polling, you can use 'find':
如果您有一个非常大的目录结构,并且需要减少轮询的开销,您可以使用“find”:
# touch -d 01/01/1970 last; while true; do if [ "`find localdir -newer last -print -quit`" ]; then touch last; rsync -avrz localdir user@host:path; else echo -ne .; fi; sleep 5; done
And I said cron may be overkill? But at least this is all just done from the command line, and can be stopped via a ctrl-C.
我说过克伦可能有点过头了?但至少这都是在命令行中完成的,可以通过ctrl-C停止。
kb
kb
#4
4
To detect changed files, you could try fam (file alteration monitor) or inotify. The latter is linux-specific, fam has a bsd port which might work on OS X. Both have userspace tools that could be used in a script together with rsync.
要检测已更改的文件,可以尝试fam(文件更改监视器)或inotify。后者是特定于linux的,fam有一个bsd端口,可以在OS x上工作,两者都有用户空间工具,可以与rsync一起使用脚本。
#5
3
I have the same issue. I loved winscp "keep remote directory up to date" command. However, in my quest to rid myself of Windows, I lost winscp. I did write a script that uses fileschanged and rsync to do something similar much closer to real time.
我也有同样的问题。我喜欢winscp“保持远程目录最新”命令。然而,为了摆脱Windows,我失去了winscp。我确实编写了一个脚本,它使用fileschanged和rsync来做类似的事情,而且更接近于实时。
How to use:
如何使用:
- Make sure you have fileschanged installed
- 确保已经安装了文件更改
- Save this script in /usr/local/bin/livesync or somewhere reachable in your $PATH and make it executable
- 将此脚本保存在/usr/local/bin/livesync或$路径中某个可访问的位置,并使其可执行
- Use Nautilus to connect to the remote host (sftp or ftp)
- 使用Nautilus来连接远程主机(sftp或ftp)
- Run this script by doing livesync SOURCE DEST
- 通过执行livesync源程序来运行这个脚本
- The DEST directory will be in /home/[username]/.gvfs/[path to ftp scp or whatever]
- 最大的目录将在/home/[username]/中。gvfs/[ftp scp路径或其他)
A Couple downsides:
几个缺点:
- It is slower than winscp (my guess is because it goes through Nautilus and has to detect changes through rsync as well)
- 它比winscp慢(我的猜测是由于它是通过Nautilus进行的,并且必须通过rsync来检测更改)
- You have to manually create the destination directory if it doesn't already exist. So if you're adding a directory, it won't detect and create the directory on the DEST side.
- 如果目标目录不存在,您必须手动创建它。因此,如果您要添加一个目录,它将不会检测并在DEST一侧创建目录。
- Probably more that I haven't noticed yet
- 我还没注意到
- Also, do not attempt to synchronize a SRC directory named "rsyncThis". That will probably not be good :)
- 另外,不要尝试同步名为“rsyncThis”的SRC目录。那可能不太好:)
#!/bin/sh
upload_files()
{
if [ "$HOMEDIR" = "." ]
then
HOMEDIR=`pwd`
fi
while read input
do
SYNCFILE=${input#$HOMEDIR}
echo -n "Sync File: $SYNCFILE..."
rsync -Cvz --temp-dir="$REMOTEDIR" "$HOMEDIR/$SYNCFILE" "$REMOTEDIR/$SYNCFILE" > /dev/null
echo "Done."
done
}
help()
{
echo "Live rsync copy from one directory to another. This will overwrite the existing files on DEST."
echo "Usage: $0 SOURCE DEST"
}
case "$1" in
rsyncThis)
HOMEDIR=$2
REMOTEDIR=$3
echo "HOMEDIR=$HOMEDIR"
echo "REMOTEDIR=$REMOTEDIR"
upload_files
;;
help)
help
;;
*)
if [ -n "$1" ] && [ -n "$2" ]
then
fileschanged -r "$1" | "$0" rsyncThis "$1" "$2"
else
help
fi
;;
esac
#6
2
The rsync
solutions are really good, especially if you're only pushing changes one way. Another great tool is unison
-- it attempts to syncronize changes in both directions. Read more at the Unison homepage.
rsync的解决方案非常好,尤其是当你只改变一种方式时。另一个很棒的工具是unison——它试图在两个方向上同步变化。请在Unison主页上阅读更多信息。
#7
1
You could always use version control, like SVN, so all you have to do is have the server run svn up on a folder every night. This runs into security issues if you are sharing your files publicly, but it works.
您可以一直使用版本控制,比如SVN,所以您所要做的就是让服务器每晚在一个文件夹上运行SVN。如果您公开共享您的文件,则会遇到安全问题,但它可以工作。
If you are using Linux though, learn to use rsync. It's really not that difficult as you can test every command with -n. Go through the man page, the basic format you will want is
如果您正在使用Linux,请学习使用rsync。这并不难,因为你可以用-n测试每个命令。浏览手册页,您需要的基本格式是
rsync [OPTION...] SRC... [USER@]HOST:DEST
rsync(选项…SRC…(USER@)主持人:服务台
the command I run from my school server to my home backup machine is this
我从学校服务器到家里的备份机运行的命令是这样的
rsync -avi --delete ~ me@homeserv:~/School/ >> BackupLog.txt
rsync -avi——删除~ me@homeserv:~/School/ >> BackupLog.txt
This takes all of the files in my home directory (~) and uses rsync's archive mode (-a), verbosly (-v), lists all of the changes made (-i), while deleting any files that don't exist anymore (--delete) and puts the in the Folder /home/me/School/ on my remote server. All of the information it prints out (what was copied, what was deleted, etc.) is also appended to the file BackupLog.txt
这将获取我的主目录(~)中的所有文件,并使用rsync的归档模式(-a), verbosly (-v)列出所做的所有更改(-i),同时删除任何不再存在的文件(- delete),并将文件放在我的远程服务器上的/home/me/School/文件夹中。它输出的所有信息(被复制的、被删除的等)也被添加到BackupLog.txt文件中
I know that's a whirlwind tour of rsync, but I hope it helps.
我知道这是一个旋风式的rsync之旅,但我希望它能有所帮助。
#8
1
It seems like perhaps you're solving the wrong problem. If you're trying to edit files on a remote computer then you might try using something like the ftp plugin for jedit. http://plugins.jedit.org/plugins/?FTP This ensures that you have only one version of the file so it can't ever be out of sync.
似乎你解决的问题是错误的。如果您试图在远程计算机上编辑文件,那么您可以尝试使用类似jedit的ftp插件。http://plugins.jedit.org/plugins/?这确保您只有一个版本的文件,所以它永远不会不同步。
#9
1
Building off of icco's suggestion of SVN, I'd actually suggest that if you are using subversion or similar for source control (and if you aren't, you should probably start) you can keep the production environment up to date by putting the command to update the repository into the post-commit hook.
根据icco对SVN的建议,我实际上建议,如果您正在使用subversion或类似的源代码控制(如果您不使用subversion或类似的方法),您可以通过使用命令将存储库更新为post-commit hook来保持生产环境的更新。
There are a lot of variables in how you'd want to do that, but what I've seen work is have the development or live site be a working copy and then have the post-commit use an ssh key with a forced command to log into the remote site and trigger an svn up on the working copy. Alternatively in the post-commit hook you could trigger an svn export on the remote machine, or a local (to the svn repository) svn export and then an rsync to the remote machine.
有很多变量如何你想这样做,但我所看到的工作是开发或生活的网站是一个工作副本,然后post-commit使用ssh密钥的强制命令登录到远程站点和触发一个svn工作副本。在提交后钩子中,您可以在远程机器上触发一个svn导出,或者在本地(到svn存储库)中触发一个svn导出,然后在远程机器上触发一个rsync。
I would be worried about things that detect changes and push them, and I'd even be worried about things that ran every minute, just because of race conditions. How do you know it's not going to transfer the file at the very same instant it's being written to? Stumble across that once or twice and you'll lose all of the time-saving advantage you had by constantly rsyncing or similar.
我会担心发现变化并推动它们的事物,甚至会担心每一分钟都在运行的事物,仅仅因为比赛条件。你怎么知道它不会在被写入文件的同时传输文件呢?偶然发现一两次,你就会因为不断地同步或类似而失去所有节省时间的优势。
#10
1
Will DropBox (http://www.getdropbox.com/) do what you want?
DropBox (http://www.getdropbox.com/)会做你想做的事吗?
#11
1
User watcher.py and rsync to automate this. Read the following step by step instructions here:
用户的观察家。py和rsync实现自动化。请阅读下面的步骤说明:
http://kushellig.de/linux-file-auto-sync-directories/
http://kushellig.de/linux-file-auto-sync-directories/
#12
1
I used to have the same setup under Windows as you, that is a local filetree (versioned) and a test environment on a remote server, which I kept mirrored in realtime with WinSCP. When I switched to Mac I had to do quite some digging before I was happy, but finally ended up using:
我以前在Windows下有与您相同的设置,即本地文件树(版本化)和远程服务器上的测试环境,我在WinSCP中实时地镜像了它们。当我切换到Mac时,我不得不在开心之前做一些挖掘工作,但最终我还是使用了:
- SmartSVN as my subversion client
- SmartSVN作为我的subversion客户端
- Sublime Text 2 as my editor (already used it on Windows)
- 崇高的文本2作为我的编辑器(已经在Windows上使用过)
- SFTP-plugin to ST2 which handles the uploading on save (sorry, can't post more than 2 links)
- SFTP-plugin to ST2,用于保存上传(不好意思,不能上传超过2个链接)
I can really recommend this setup, hope it helps!
我真的可以推荐这个设置,希望它有帮助!
#13
0
You can also use Fetch as an SFTP client, and then edit files directly on the server from within that. There are also SSHFS (mount an ssh folder as a Volume) options. This is in line with what stimms said - are you sure you want stuff kept in sync, or just want to edit files on the server?
您还可以将Fetch用作SFTP客户端,然后从该客户端直接编辑服务器上的文件。还有SSHFS(将ssh文件夹挂载为卷)选项。这与stimms所说的一致——您确定要保持内容同步,还是只想编辑服务器上的文件?
OS X has it's own file notifications system - this is what Spotlight is based upon. I haven't heard of any program that uses this to then keep things in sync, but it's certainly conceivable.
OS X有自己的文件通知系统——这是Spotlight的基础。我还没听说过有哪个程序用它来保持同步,但这是可以想象的。
I personally use RCS for this type of thing:- whilst it's got a manual aspect, it's unlikely I want to push something to even the test server from my dev machine without testing it first. And if I am working on a development server, then I use one of the options given above.
我个人在这类事情上使用RCS:-虽然它有一个手动方面,但是我不太可能在不进行测试的情况下,将一些东西从我的开发机器上推送到测试服务器上。如果我在开发服务器上工作,那么我将使用上面给出的选项之一。
#14
0
Well, I had the same kind of problem and it is possible using these together: rsync, SSH Passwordless Login, Watchdog (a Python sync utility) and Terminal Notifier (an OS X notification utility made with Ruby. Not needed, but helps to know when the sync has finished).
好吧,我遇到了同样的问题,并且可以一起使用:rsync、SSH passwordlogin、Watchdog (Python sync实用程序)和终端通知器(使用Ruby编写的OS X通知实用程序)。不需要,但有助于知道同步何时完成)。
-
I created the key to Passwordless Login using this tutorial from Dreamhost wiki: http://cl.ly/MIw5
我使用Dreamhost wiki: http://cl.ly/MIw5创建了无密码登录的密钥
1.1. When you finish, test if everything is ok… if you can't Passwordless Login, maybe you have to try afp mount. Dreamhost (where my site is) does not allow afp mount, but allows Passwordless Login. In terminal, type:
1.1。当你完成后,测试是否一切正常…如果你不能无密码登录,也许你必须试试afp mount。Dreamhost(我的站点在那里)不允许afp挂载,但是允许无密码登录。在终端,输入:
ssh username@host.com
You should login without passwords being asked :Pssh username@host.com您应该在没有被要求密码的情况下登录:P。
-
I installed the Terminal Notifier from the Github page: http://cl.ly/MJ5x
我安装了来自Github页面的终端通知器:http://cl.ly/MJ5x
2.1. I used the Gem installer command. In Terminal, type:
2.1。我使用了Gem安装程序命令。在终端,输入:
gem install terminal-notifier
gem安装terminal-notifier
2.3. Test if the notification works.In Terminal, type:
2.3。测试通知是否有效。在终端,输入:
terminal-notifier -message "Starting sync"
terminal-notifier消息“同步”
-
Create a sh script to test the rsync + notification. Save it anywhere you like, with the name you like. In this example, I'll call it ~/Scripts/sync.sh I used the ".sh extension, but I don't know if its needed.
创建一个sh脚本来测试rsync +通知。把它存到你喜欢的地方,用你喜欢的名字。在这个例子中,我将它命名为~/Scripts/sync。我用了"。但是我不知道是否需要。
#!/bin/bash terminal-notifier -message "Starting sync" rsync -azP ~/Sites/folder/ user@host.com:site_folder/ terminal-notifier -message "Sync has finished"
# !/bin/bash终端通知-消息“启动同步”rsync -azP ~/ site /文件夹/ user@host.com:site_folder/终止通知-消息“同步已完成”
3.1. Remember to give execution permission to this sh script. In Terminal, type:
3.1。记住要给这个sh脚本执行权限。在终端,输入:
sudo chmod 777 ~/Scripts/sync.sh
3.2. Run the script and verify if the messages are displayed correctly and the rsync actually sync your local folder with the remote folder.sudo chmod 777 ~ /脚本/同步。上海3.2。运行脚本并验证消息是否显示正确,rsync实际上将本地文件夹与远程文件夹同步。
-
Finally, I downloaded and installed Watchdog from the Github page: http://cl.ly/MJfb
最后,我从Github页面下载并安装了Watchdog: http://cl.ly/MJfb
4.1. First, I installed the libyaml dependency using Brew (there are lot's of help how to install Brew - like an "aptitude" for OS X). In Terminal, type:
4.1。首先,我使用Brew来安装利比亚的依赖性(有很多的帮助如何安装Brew -就像OS X的“天赋”),在终端,类型:
brew install libyaml
酿造安装libyaml
4.2. Then, I used the "easy_install command". Go the folder of Watchdog, and type in Terminal:
4.2。然后,我使用了“easy_install命令”。进入看门狗文件夹,输入终端:
easy_install watchdog
easy_install监督
-
Now, everything is installed! Go the folder you want to be synced, change this code to your needs, and type in Terminal:
现在,所有的软件都已经安装好了!进入你想要同步的文件夹,根据你的需要更改此代码,并输入终端:
watchmedo shell-command --patterns="*.php;*.txt;*.js;*.css" \ --recursive \ --command='~/Scripts/Sync.sh' \ .
It has to be EXACTLY this way, with the slashes and line breaks, so you'll have to copy these lines to a text editor, change the script, paste in terminal and press return.
它必须是这样的,使用斜线和换行符,所以您必须将这些行复制到文本编辑器,修改脚本,在终端中粘贴并按return。
I tried without the line breaks, and it doesn't work!
我试过没有断线,但不行!
In my Mac, I always get an error, but it doesn't seem to affect anything:
在我的Mac电脑上,我总是会出错,但似乎不会影响到任何东西:
/Library/Python/2.7/site-packages/argh-0.22.0-py2.7.egg/argh/completion.py:84: UserWarning: Bash completion not available. Install argcomplete.
/图书馆/ Python / 2.7 /网站/ argh-0.22.0-py2.7.egg /啊/完成。py:84:用户警告:Bash完成不可用。安装argcomplete。
Now, made some changes in a file inside the folder, and watch the magic!
现在,在文件夹内的一个文件中做一些更改,并观看魔术!
#15
0
I'm using this little Ruby-Script:
我用的是这个小ruby脚本:
#!/usr/bin/env ruby
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Rsyncs 2Folders
#
# watchAndSync by Mike Mitterer, 2014 <http://www.MikeMitterer.at>
# with credit to Brett Terpstra <http://brettterpstra.com>
# and Carlo Zottmann <https://github.com/carlo/haml-sass-file-watcher>
# Found link on: http://brettterpstra.com/2011/03/07/watch-for-file-changes-and-refresh-your-browser-automatically/
#
trap("SIGINT") { exit }
if ARGV.length < 2
puts "Usage: #{$0} watch_folder sync_folder"
puts "Example: #{$0} web keepInSync"
exit
end
dev_extension = 'dev'
filetypes = ['css','html','htm','less','js', 'dart']
watch_folder = ARGV[0]
sync_folder = ARGV[1]
puts "Watching #{watch_folder} and subfolders for changes in project files..."
puts "Syncing with #{sync_folder}..."
while true do
files = []
filetypes.each {|type|
files += Dir.glob( File.join( watch_folder, "**", "*.#{type}" ) )
}
new_hash = files.collect {|f| [ f, File.stat(f).mtime.to_i ] }
hash ||= new_hash
diff_hash = new_hash - hash
unless diff_hash.empty?
hash = new_hash
diff_hash.each do |df|
puts "Detected change in #{df[0]}, syncing..."
system("rsync -avzh #{watch_folder} #{sync_folder}")
end
end
sleep 1
end
Adapt it for your needs!
为你的需要调整它!
#1
16
How "real-time" do you want the syncing? I would still lean toward rsync since you know it is going to be fully supported on both platforms (Windows, too, with cygwin) and you can run it via a cron job. I have a super-simple bash file that I run on my system (this does not remove old files):
如何“实时”同步?我仍然倾向于使用rsync,因为您知道它将在两个平台上(Windows也支持cygwin),您可以通过cron作业运行它。我有一个超级简单的bash文件,我在我的系统上运行(这不会删除旧文件):
#!/bin/sh
rsync -avrz --progress --exclude-from .rsync_exclude_remote . remote_login@remote_computer:remote_dir
# options
# -a archive
# -v verbose
# -r recursive
# -z compress
Your best bet is to set it up and try it out. The -n (--dry-run)
option is your friend!
你最好的办法就是把它设置好,然后试一试。-n (- run)选项是你的朋友!
Keep in mind that rsync (at least in cygwin) does not support unicode file names (as of 16 Aug 2008).
请记住,rsync(至少在cygwin中)不支持unicode文件名(截至2008年8月16日)。
#2
39
lsyncd seems to be the perfect solution. it combines inotify (kernel builtin function which watches for file changes in a directory trees) and rsync (cross platform file-syncing-tool).
lsyncd似乎是完美的解决方案。它结合了inotify(内核构建函数,监视目录树中的文件更改)和rsync(跨平台文件同步工具)。
lsyncd -rsyncssh /home remotehost.org backup-home/
Quote from github:
从github报价:
Lsyncd watches a local directory trees event monitor interface (inotify or fsevents). It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronize the changes. By default this is rsync. Lsyncd is thus a light-weight live mirror solution that is comparatively easy to install not requiring new filesystems or blockdevices and does not hamper local filesystem performance.
Lsyncd监视本地目录树事件监视器接口(inotify或fsevents)。它聚合并组合事件几秒钟,然后生成一个(或多个)进程来同步更改。默认情况下这是rsync。因此,Lsyncd是一个轻量级的活动镜像解决方案,相对容易安装,不需要新的文件系统或块设备,并且不会影响本地文件系统的性能。
#3
8
What you want to do for linux remote access is use 'sshfs' - the SSH File System.
对于linux远程访问,您需要做的是使用“sshfs”——SSH文件系统。
# sshfs username@host:path/to/directory local_dir
Then treat it like an network mount, which it is...
然后把它当作一个网络挂载,它是…
A bit more detail, like how to set it up so you can do this as a regular user, on my blog
更多的细节,比如如何设置它,以便作为一个普通用户,你可以在我的博客上这样做
If you want the asynchronous behavior of winSCP, you'll want to use rsync combined with something that executes it periodically. The cron solution above works, but may be overkill for the winscp use case.
如果您想要winSCP的异步行为,您将希望使用rsync和一些定期执行的东西结合使用。上面的cron解决方案是有效的,但是对于winscp用例来说可能有些过头了。
The following command will execute rsync every 5 seconds to push content to the remote host. You can adjust the sleep time as needed to reduce server load.
下面的命令将每5秒执行一次rsync,将内容推送到远程主机。您可以根据需要调整睡眠时间,以减少服务器负载。
# while true; do rsync -avrz localdir user@host:path; sleep 5; done
If you have a very large directory structure and need to reduce the overhead of the polling, you can use 'find':
如果您有一个非常大的目录结构,并且需要减少轮询的开销,您可以使用“find”:
# touch -d 01/01/1970 last; while true; do if [ "`find localdir -newer last -print -quit`" ]; then touch last; rsync -avrz localdir user@host:path; else echo -ne .; fi; sleep 5; done
And I said cron may be overkill? But at least this is all just done from the command line, and can be stopped via a ctrl-C.
我说过克伦可能有点过头了?但至少这都是在命令行中完成的,可以通过ctrl-C停止。
kb
kb
#4
4
To detect changed files, you could try fam (file alteration monitor) or inotify. The latter is linux-specific, fam has a bsd port which might work on OS X. Both have userspace tools that could be used in a script together with rsync.
要检测已更改的文件,可以尝试fam(文件更改监视器)或inotify。后者是特定于linux的,fam有一个bsd端口,可以在OS x上工作,两者都有用户空间工具,可以与rsync一起使用脚本。
#5
3
I have the same issue. I loved winscp "keep remote directory up to date" command. However, in my quest to rid myself of Windows, I lost winscp. I did write a script that uses fileschanged and rsync to do something similar much closer to real time.
我也有同样的问题。我喜欢winscp“保持远程目录最新”命令。然而,为了摆脱Windows,我失去了winscp。我确实编写了一个脚本,它使用fileschanged和rsync来做类似的事情,而且更接近于实时。
How to use:
如何使用:
- Make sure you have fileschanged installed
- 确保已经安装了文件更改
- Save this script in /usr/local/bin/livesync or somewhere reachable in your $PATH and make it executable
- 将此脚本保存在/usr/local/bin/livesync或$路径中某个可访问的位置,并使其可执行
- Use Nautilus to connect to the remote host (sftp or ftp)
- 使用Nautilus来连接远程主机(sftp或ftp)
- Run this script by doing livesync SOURCE DEST
- 通过执行livesync源程序来运行这个脚本
- The DEST directory will be in /home/[username]/.gvfs/[path to ftp scp or whatever]
- 最大的目录将在/home/[username]/中。gvfs/[ftp scp路径或其他)
A Couple downsides:
几个缺点:
- It is slower than winscp (my guess is because it goes through Nautilus and has to detect changes through rsync as well)
- 它比winscp慢(我的猜测是由于它是通过Nautilus进行的,并且必须通过rsync来检测更改)
- You have to manually create the destination directory if it doesn't already exist. So if you're adding a directory, it won't detect and create the directory on the DEST side.
- 如果目标目录不存在,您必须手动创建它。因此,如果您要添加一个目录,它将不会检测并在DEST一侧创建目录。
- Probably more that I haven't noticed yet
- 我还没注意到
- Also, do not attempt to synchronize a SRC directory named "rsyncThis". That will probably not be good :)
- 另外,不要尝试同步名为“rsyncThis”的SRC目录。那可能不太好:)
#!/bin/sh
upload_files()
{
if [ "$HOMEDIR" = "." ]
then
HOMEDIR=`pwd`
fi
while read input
do
SYNCFILE=${input#$HOMEDIR}
echo -n "Sync File: $SYNCFILE..."
rsync -Cvz --temp-dir="$REMOTEDIR" "$HOMEDIR/$SYNCFILE" "$REMOTEDIR/$SYNCFILE" > /dev/null
echo "Done."
done
}
help()
{
echo "Live rsync copy from one directory to another. This will overwrite the existing files on DEST."
echo "Usage: $0 SOURCE DEST"
}
case "$1" in
rsyncThis)
HOMEDIR=$2
REMOTEDIR=$3
echo "HOMEDIR=$HOMEDIR"
echo "REMOTEDIR=$REMOTEDIR"
upload_files
;;
help)
help
;;
*)
if [ -n "$1" ] && [ -n "$2" ]
then
fileschanged -r "$1" | "$0" rsyncThis "$1" "$2"
else
help
fi
;;
esac
#6
2
The rsync
solutions are really good, especially if you're only pushing changes one way. Another great tool is unison
-- it attempts to syncronize changes in both directions. Read more at the Unison homepage.
rsync的解决方案非常好,尤其是当你只改变一种方式时。另一个很棒的工具是unison——它试图在两个方向上同步变化。请在Unison主页上阅读更多信息。
#7
1
You could always use version control, like SVN, so all you have to do is have the server run svn up on a folder every night. This runs into security issues if you are sharing your files publicly, but it works.
您可以一直使用版本控制,比如SVN,所以您所要做的就是让服务器每晚在一个文件夹上运行SVN。如果您公开共享您的文件,则会遇到安全问题,但它可以工作。
If you are using Linux though, learn to use rsync. It's really not that difficult as you can test every command with -n. Go through the man page, the basic format you will want is
如果您正在使用Linux,请学习使用rsync。这并不难,因为你可以用-n测试每个命令。浏览手册页,您需要的基本格式是
rsync [OPTION...] SRC... [USER@]HOST:DEST
rsync(选项…SRC…(USER@)主持人:服务台
the command I run from my school server to my home backup machine is this
我从学校服务器到家里的备份机运行的命令是这样的
rsync -avi --delete ~ me@homeserv:~/School/ >> BackupLog.txt
rsync -avi——删除~ me@homeserv:~/School/ >> BackupLog.txt
This takes all of the files in my home directory (~) and uses rsync's archive mode (-a), verbosly (-v), lists all of the changes made (-i), while deleting any files that don't exist anymore (--delete) and puts the in the Folder /home/me/School/ on my remote server. All of the information it prints out (what was copied, what was deleted, etc.) is also appended to the file BackupLog.txt
这将获取我的主目录(~)中的所有文件,并使用rsync的归档模式(-a), verbosly (-v)列出所做的所有更改(-i),同时删除任何不再存在的文件(- delete),并将文件放在我的远程服务器上的/home/me/School/文件夹中。它输出的所有信息(被复制的、被删除的等)也被添加到BackupLog.txt文件中
I know that's a whirlwind tour of rsync, but I hope it helps.
我知道这是一个旋风式的rsync之旅,但我希望它能有所帮助。
#8
1
It seems like perhaps you're solving the wrong problem. If you're trying to edit files on a remote computer then you might try using something like the ftp plugin for jedit. http://plugins.jedit.org/plugins/?FTP This ensures that you have only one version of the file so it can't ever be out of sync.
似乎你解决的问题是错误的。如果您试图在远程计算机上编辑文件,那么您可以尝试使用类似jedit的ftp插件。http://plugins.jedit.org/plugins/?这确保您只有一个版本的文件,所以它永远不会不同步。
#9
1
Building off of icco's suggestion of SVN, I'd actually suggest that if you are using subversion or similar for source control (and if you aren't, you should probably start) you can keep the production environment up to date by putting the command to update the repository into the post-commit hook.
根据icco对SVN的建议,我实际上建议,如果您正在使用subversion或类似的源代码控制(如果您不使用subversion或类似的方法),您可以通过使用命令将存储库更新为post-commit hook来保持生产环境的更新。
There are a lot of variables in how you'd want to do that, but what I've seen work is have the development or live site be a working copy and then have the post-commit use an ssh key with a forced command to log into the remote site and trigger an svn up on the working copy. Alternatively in the post-commit hook you could trigger an svn export on the remote machine, or a local (to the svn repository) svn export and then an rsync to the remote machine.
有很多变量如何你想这样做,但我所看到的工作是开发或生活的网站是一个工作副本,然后post-commit使用ssh密钥的强制命令登录到远程站点和触发一个svn工作副本。在提交后钩子中,您可以在远程机器上触发一个svn导出,或者在本地(到svn存储库)中触发一个svn导出,然后在远程机器上触发一个rsync。
I would be worried about things that detect changes and push them, and I'd even be worried about things that ran every minute, just because of race conditions. How do you know it's not going to transfer the file at the very same instant it's being written to? Stumble across that once or twice and you'll lose all of the time-saving advantage you had by constantly rsyncing or similar.
我会担心发现变化并推动它们的事物,甚至会担心每一分钟都在运行的事物,仅仅因为比赛条件。你怎么知道它不会在被写入文件的同时传输文件呢?偶然发现一两次,你就会因为不断地同步或类似而失去所有节省时间的优势。
#10
1
Will DropBox (http://www.getdropbox.com/) do what you want?
DropBox (http://www.getdropbox.com/)会做你想做的事吗?
#11
1
User watcher.py and rsync to automate this. Read the following step by step instructions here:
用户的观察家。py和rsync实现自动化。请阅读下面的步骤说明:
http://kushellig.de/linux-file-auto-sync-directories/
http://kushellig.de/linux-file-auto-sync-directories/
#12
1
I used to have the same setup under Windows as you, that is a local filetree (versioned) and a test environment on a remote server, which I kept mirrored in realtime with WinSCP. When I switched to Mac I had to do quite some digging before I was happy, but finally ended up using:
我以前在Windows下有与您相同的设置,即本地文件树(版本化)和远程服务器上的测试环境,我在WinSCP中实时地镜像了它们。当我切换到Mac时,我不得不在开心之前做一些挖掘工作,但最终我还是使用了:
- SmartSVN as my subversion client
- SmartSVN作为我的subversion客户端
- Sublime Text 2 as my editor (already used it on Windows)
- 崇高的文本2作为我的编辑器(已经在Windows上使用过)
- SFTP-plugin to ST2 which handles the uploading on save (sorry, can't post more than 2 links)
- SFTP-plugin to ST2,用于保存上传(不好意思,不能上传超过2个链接)
I can really recommend this setup, hope it helps!
我真的可以推荐这个设置,希望它有帮助!
#13
0
You can also use Fetch as an SFTP client, and then edit files directly on the server from within that. There are also SSHFS (mount an ssh folder as a Volume) options. This is in line with what stimms said - are you sure you want stuff kept in sync, or just want to edit files on the server?
您还可以将Fetch用作SFTP客户端,然后从该客户端直接编辑服务器上的文件。还有SSHFS(将ssh文件夹挂载为卷)选项。这与stimms所说的一致——您确定要保持内容同步,还是只想编辑服务器上的文件?
OS X has it's own file notifications system - this is what Spotlight is based upon. I haven't heard of any program that uses this to then keep things in sync, but it's certainly conceivable.
OS X有自己的文件通知系统——这是Spotlight的基础。我还没听说过有哪个程序用它来保持同步,但这是可以想象的。
I personally use RCS for this type of thing:- whilst it's got a manual aspect, it's unlikely I want to push something to even the test server from my dev machine without testing it first. And if I am working on a development server, then I use one of the options given above.
我个人在这类事情上使用RCS:-虽然它有一个手动方面,但是我不太可能在不进行测试的情况下,将一些东西从我的开发机器上推送到测试服务器上。如果我在开发服务器上工作,那么我将使用上面给出的选项之一。
#14
0
Well, I had the same kind of problem and it is possible using these together: rsync, SSH Passwordless Login, Watchdog (a Python sync utility) and Terminal Notifier (an OS X notification utility made with Ruby. Not needed, but helps to know when the sync has finished).
好吧,我遇到了同样的问题,并且可以一起使用:rsync、SSH passwordlogin、Watchdog (Python sync实用程序)和终端通知器(使用Ruby编写的OS X通知实用程序)。不需要,但有助于知道同步何时完成)。
-
I created the key to Passwordless Login using this tutorial from Dreamhost wiki: http://cl.ly/MIw5
我使用Dreamhost wiki: http://cl.ly/MIw5创建了无密码登录的密钥
1.1. When you finish, test if everything is ok… if you can't Passwordless Login, maybe you have to try afp mount. Dreamhost (where my site is) does not allow afp mount, but allows Passwordless Login. In terminal, type:
1.1。当你完成后,测试是否一切正常…如果你不能无密码登录,也许你必须试试afp mount。Dreamhost(我的站点在那里)不允许afp挂载,但是允许无密码登录。在终端,输入:
ssh username@host.com
You should login without passwords being asked :Pssh username@host.com您应该在没有被要求密码的情况下登录:P。
-
I installed the Terminal Notifier from the Github page: http://cl.ly/MJ5x
我安装了来自Github页面的终端通知器:http://cl.ly/MJ5x
2.1. I used the Gem installer command. In Terminal, type:
2.1。我使用了Gem安装程序命令。在终端,输入:
gem install terminal-notifier
gem安装terminal-notifier
2.3. Test if the notification works.In Terminal, type:
2.3。测试通知是否有效。在终端,输入:
terminal-notifier -message "Starting sync"
terminal-notifier消息“同步”
-
Create a sh script to test the rsync + notification. Save it anywhere you like, with the name you like. In this example, I'll call it ~/Scripts/sync.sh I used the ".sh extension, but I don't know if its needed.
创建一个sh脚本来测试rsync +通知。把它存到你喜欢的地方,用你喜欢的名字。在这个例子中,我将它命名为~/Scripts/sync。我用了"。但是我不知道是否需要。
#!/bin/bash terminal-notifier -message "Starting sync" rsync -azP ~/Sites/folder/ user@host.com:site_folder/ terminal-notifier -message "Sync has finished"
# !/bin/bash终端通知-消息“启动同步”rsync -azP ~/ site /文件夹/ user@host.com:site_folder/终止通知-消息“同步已完成”
3.1. Remember to give execution permission to this sh script. In Terminal, type:
3.1。记住要给这个sh脚本执行权限。在终端,输入:
sudo chmod 777 ~/Scripts/sync.sh
3.2. Run the script and verify if the messages are displayed correctly and the rsync actually sync your local folder with the remote folder.sudo chmod 777 ~ /脚本/同步。上海3.2。运行脚本并验证消息是否显示正确,rsync实际上将本地文件夹与远程文件夹同步。
-
Finally, I downloaded and installed Watchdog from the Github page: http://cl.ly/MJfb
最后,我从Github页面下载并安装了Watchdog: http://cl.ly/MJfb
4.1. First, I installed the libyaml dependency using Brew (there are lot's of help how to install Brew - like an "aptitude" for OS X). In Terminal, type:
4.1。首先,我使用Brew来安装利比亚的依赖性(有很多的帮助如何安装Brew -就像OS X的“天赋”),在终端,类型:
brew install libyaml
酿造安装libyaml
4.2. Then, I used the "easy_install command". Go the folder of Watchdog, and type in Terminal:
4.2。然后,我使用了“easy_install命令”。进入看门狗文件夹,输入终端:
easy_install watchdog
easy_install监督
-
Now, everything is installed! Go the folder you want to be synced, change this code to your needs, and type in Terminal:
现在,所有的软件都已经安装好了!进入你想要同步的文件夹,根据你的需要更改此代码,并输入终端:
watchmedo shell-command --patterns="*.php;*.txt;*.js;*.css" \ --recursive \ --command='~/Scripts/Sync.sh' \ .
It has to be EXACTLY this way, with the slashes and line breaks, so you'll have to copy these lines to a text editor, change the script, paste in terminal and press return.
它必须是这样的,使用斜线和换行符,所以您必须将这些行复制到文本编辑器,修改脚本,在终端中粘贴并按return。
I tried without the line breaks, and it doesn't work!
我试过没有断线,但不行!
In my Mac, I always get an error, but it doesn't seem to affect anything:
在我的Mac电脑上,我总是会出错,但似乎不会影响到任何东西:
/Library/Python/2.7/site-packages/argh-0.22.0-py2.7.egg/argh/completion.py:84: UserWarning: Bash completion not available. Install argcomplete.
/图书馆/ Python / 2.7 /网站/ argh-0.22.0-py2.7.egg /啊/完成。py:84:用户警告:Bash完成不可用。安装argcomplete。
Now, made some changes in a file inside the folder, and watch the magic!
现在,在文件夹内的一个文件中做一些更改,并观看魔术!
#15
0
I'm using this little Ruby-Script:
我用的是这个小ruby脚本:
#!/usr/bin/env ruby
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Rsyncs 2Folders
#
# watchAndSync by Mike Mitterer, 2014 <http://www.MikeMitterer.at>
# with credit to Brett Terpstra <http://brettterpstra.com>
# and Carlo Zottmann <https://github.com/carlo/haml-sass-file-watcher>
# Found link on: http://brettterpstra.com/2011/03/07/watch-for-file-changes-and-refresh-your-browser-automatically/
#
trap("SIGINT") { exit }
if ARGV.length < 2
puts "Usage: #{$0} watch_folder sync_folder"
puts "Example: #{$0} web keepInSync"
exit
end
dev_extension = 'dev'
filetypes = ['css','html','htm','less','js', 'dart']
watch_folder = ARGV[0]
sync_folder = ARGV[1]
puts "Watching #{watch_folder} and subfolders for changes in project files..."
puts "Syncing with #{sync_folder}..."
while true do
files = []
filetypes.each {|type|
files += Dir.glob( File.join( watch_folder, "**", "*.#{type}" ) )
}
new_hash = files.collect {|f| [ f, File.stat(f).mtime.to_i ] }
hash ||= new_hash
diff_hash = new_hash - hash
unless diff_hash.empty?
hash = new_hash
diff_hash.each do |df|
puts "Detected change in #{df[0]}, syncing..."
system("rsync -avzh #{watch_folder} #{sync_folder}")
end
end
sleep 1
end
Adapt it for your needs!
为你的需要调整它!