使用 NFS 作为 Vagrant 同步系统时忽略同步的文件/目录

8

有没有办法让NFS忽略同步文件夹中指定的文件和/或目录?我已经在rsync中完成了这个操作(rsync__exclude),但是我没有找到任何关于NFS的参考资料。我也在寻找SMB的解决方案。有什么想法吗?

3个回答

8

在我的情况下,我必须保持缓存和日志文件不同步,我找到的解决方案是创建符号链接而不是缓存和日志文件夹(例如 app/cacheapp/log),该符号链接指向同步文件夹之外的目录(例如 /home/vagrant/project/cache)。然后,app/cache 内部的文件不会被同步。希望这有所帮助。


4
我的声望还不够高,不能评论上面的回答,但我遇到了完全相同的问题。我必须进行一些努力并找出以下细节:
符号链接必须在您的虚拟机中。例如:
vagrant ssh
cd your/webapp
mkdir outside/your/webapp
ln -s outside/your/webapp cache

现在,符号链接将显示在您的项目文件夹中,但实际上您不会在其之间同步任何文件。

当然,/home/vagrant/project/cache 在同步文件夹之外,但在虚拟机内部。 - Manolo
也许可以说,在这种情况下,“outsite/folder”需要额外的文件权限。 - FreeLightman

0
我成功地将NFS和RSync结合起来了。在RSync中,我们可以排除NFS文件夹
这是我在Symfony 3.4项目的vagrantfile中的设置。除了/var文件夹外,每个文件夹都将使用NFS。
biDirectionalNFSFolders = []

Dir.foreach('.') do |folder|

    # Skip if not a directory?
    # Skip if /var folder
    # Skip if . or .. folder
    next if !File.directory?(folder) or folder == 'var' or folder == '.' or folder == '..'

    # This folder can be NFS synced
    fullPath = '/htdocs/' + folder
    biDirectionalNFSFolders.push(fullPath)
    config.vm.synced_folder "." + fullPath, "/vagrant" + fullPath, type: "nfs", mount_options: ['rw', 'vers=3', 'tcp', 'fsc', 'nolock', 'actimeo=2']

end

# The remaining folders (/var only in this case) can then be Rsynced, the NFS folders will be excluded
config.vm.synced_folder ".", "/vagrant", type: "rsync",
    rsync__exclude: biDirectionalNFSFolders

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接