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

3

8

Is there any way to make 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. Any ideas?

Bawl answered 16/6, 2015 at 19:5 Comment(0)
B
8

In my case I had to keep cache and log files unsynchronized, and the solution I found out was to create a symbolic link instead of the cache and log folders (e.g. app/cache and app/log) which points to a directory outside the synchronized folder (e.g. /home/vagrant/project/cache). Then, the files inside app/cache are not synchronized. Hope it helps.

Bawl answered 11/8, 2015 at 9:25 Comment(0)
R
4

My rep isn't high enough to comment on the above answer, I had the exact same problem. I had to do a little work and figure this detail out:

The symlink must be in your virtual machine. So for example:

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

Now the symlink will show up in your project folder, but you won't actually be synchronizing any files across it.

Riddick answered 9/3, 2017 at 22:1 Comment(2)
Of course, /home/vagrant/project/cache is outside the sync folder, but inside the VM.Bawl
Maybe it will be a good point to say that in this case outsite/folder needs additional file permissions.Budge
U
0

I managed to combine NFS and RSync. In the RSync we can exclude the NFS folders

This is what I have in my vagrantfile for a Symfony 3.4 project. Every folder will be NFS except the /var folder

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
Unstring answered 11/7, 2020 at 12:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.