【问题标题】:Ignore synced folder files/directories with NFS as sync system for Vagrant忽略使用 NFS 作为 Vagrant 同步系统的同步文件夹文件/目录
【发布时间】:2015-09-01 18:34:57
【问题描述】:

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

【问题讨论】:

    标签: vagrant virtualbox rsync nfs smb


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我的代表不足以评论上述答案,我遇到了完全相同的问题。我必须做一些工作并弄清楚这个细节:

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

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

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

      【讨论】:

      • 当然,/home/vagrant/project/cache 在同步文件夹之外,但在 VM 内。
      • 在这种情况下,outsite/folder 需要额外的文件权限也许是个好主意。
      【解决方案3】:

      我设法将 NFS 和 RSync 结合起来。在 RSync 中,我们可以排除 NFS 文件夹

      这是我的 vagrantfile 中用于 Symfony 3.4 项目的内容。除了 /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
      

      【讨论】:

        猜你喜欢
        • 2014-12-29
        • 2016-04-25
        • 2016-01-08
        • 2019-07-26
        • 1970-01-01
        • 2017-01-01
        • 2016-06-18
        • 2016-03-21
        • 1970-01-01
        相关资源
        最近更新 更多