Copy files from guest to host the first time with rsync using Vagrant

rsyncvagrantvirtualbox

When doing vagrant up a "shell" provision download some files into the synced folder. Those files should be also copied to the host machine synced folder, so that the project would be available from the host. When using the NFS to sync, this is done automatically, but not with rsync. Is there any way to achieve this using rsync with Vagrant? This is the synced folder configuration:

config.vm.synced_folder "./", "/vagrant", type: "rsync", owner: "www-data",
rsync__exclude: [".git", "project1/app/cache", "project1/app/logs"],
rsync__args: ["--no-owner", "--verbose", "--archive", "-z", "--copy-links"]

Best Answer

According to the Documentation, rsync is only a one-way synchronization in vagrant. This means that you either have to use a different mechanism like nfs for a sync back from the guest to the host or else that you'd have to implement some back-sync mechanism of your own like running a rsync command manually on the host.

One might write a rsync-back extension(plugin) to vagrant. I am not aware of an existing plugin to achieve that.

If the virtualbox guest extensions are installed in your guest, you might also want to take a look at the virtualbox shared folder mechansim vboxsf as a transport for varant's synced folder instead of nfs and rsync.

Related Topic