Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get files from guest to host in vagrant

Can I retrieve the files from my vagrant machine (guest) and sync it to my host machine?

I know sync folders work the other way around but I was hoping there is a way to make it in reverse? Instead of synching files from the host machine to the guest machine; retrieve the files from inside the guest machine and have it exposed on the host machine.

Thanks.

like image 748
n0minal Avatar asked Apr 28 '14 11:04

n0minal


4 Answers

Why not just put them in the /vagrant folder of your vagrant vm. This is a special mounted folder from the host (where Vagrantfile) resides to the guest.

This way you do not have to worry about doing any other copy operations between hosts.

$ ls
Vagrantfile
$ vagrant ssh
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-42-generic x86_64)
Last login: Wed Oct 12 12:05:53 2016 from 10.0.2.2
vagrant@vagrant-virtualbox:~$ ls /vagrant
Vagrantfile
vagrant@vagrant-virtualbox:~$ cd /vagrant
vagrant@vagrant-virtualbox:/vagrant$ touch hello
vagrant@vagrant-virtualbox:/vagrant$ exit
logout
Connection to 127.0.0.1 closed.
$ ls
Vagrantfile             hello
$ 
like image 83
Aviator Avatar answered Oct 19 '22 16:10

Aviator


have you tried to scp files between your host and your virtual machine ? As I remember, the ssh login and password are "vagrant".

Something like this could do the job :

scp vagrant@<vm_ip>:<path_to_file> <path_to_dest_on_your_host>

like image 37
jiop Avatar answered Oct 19 '22 16:10

jiop


Using scp with private key will make this much easy!

scp -i ./.vagrant/machines/default/virtualbox/private_key -r -P2222 [email protected]:/home/vagrant/somefolder ./
like image 29
james h Avatar answered Oct 19 '22 18:10

james h


You may want to try vagrant-rsync-back. I've not tried it yet.

like image 32
volvox Avatar answered Oct 19 '22 18:10

volvox