忽略使用 NFS 作为 Vagrant 同步系统的同步文件夹 files/directories

Ignore synced folder files/directories with NFS as sync system for Vagrant

有什么方法可以制作NFS to ignore specified files and/or directories from the synced folder? I have done it with rsync (rsync__exclude), but don't find any reference for NFS. I'm also looking for a solution for SMB。有什么想法吗?

在我的例子中,我不得不保持缓存和日志文件不同步,我发现的解决方案是创建一个符号 link 而不是缓存和日志文件夹(例如 app/cacheapp/log) 指向同步文件夹之外的目录(例如 /home/vagrant/project/cache)。那么,app/cache里面的文件是不同步的。希望对你有帮助。

我的代表不够高,无法对上述答案发表评论,我遇到了完全相同的问题。我不得不做一些工作并弄清楚这个细节:

符号链接必须在您的虚拟机中。例如:

vagrant ssh
cd your/webapp
mkdir outside/your/webapp
ln -s outside/your/webapp cache

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

我设法结合了 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