Skip to content

Vagrant: file transfers and snapshots

Last updated on 2019-04-06

First things first

Installing and initializing Vagrant

File transfers

Uploading files to your VM

Without the need for VirtualBox Guest Additions (or other platforms’ equivalent), Vagrant copies the contents of the host’s project directory into the /vagrant directory on the VM – not /home/vagrant, just /vagrant.
Note: the host’s project directory is the one which contains the Vagrantfile – which, by the way, also gets copied over.

This synchronization happens every time you issue vagrant up or vagrant reload; however, you can trigger it with a couple commands even if the VM is currently running:

  • vagrant rsync will upload any files from the host’s project directory that haven’t already been copied to the VM.
  • vagrant rsync-auto will start a process that monitors the host’s project directory and automatically uploads new files to the VM.

You may find it useful to execute vagrant rsync-auto as a background process.

Please note: the above commands expect the working directory to be the host’s project directory. Issuing them outside of the project directory will generate a warning followed by instructions on how to obtain an ID that would allow you to issue commands against a specific instance regardless of your current working directory.

For more details on Vagrant’s RSync feature, see https://www.vagrantup.com/docs/synced-folders/rsync.html.

Downloading files from your VM

… or from any other machine that has Python installed:

Managing snapshots

If your VM were a game, taking a snapshot would be saving your game. This means that, after you’ve screwed everything up, you can restore a previously-saved VM state (a snapshot). Priceless.

Vagrant allows you to manage snapshots with the following commands:

  • vagrant snapshot list, to see all saved snapshots
  • vagrant snapshot save <name>, to create a named snapshot
  • vagrant snapshot restore <name>, to restore a named snapshot
  • vagrant snapshot delete <name>, you get the idea

For quicker operations, push and pop variations exist:

  • vagrant snapshot push, creates a new “pushed” snapshot.
  • vagrant snapshot pop, restores and deletes the most recent “pushed” snapshot. Named snapshots will not be restored and/or deleted with this command.

Please note: the above commands expect the working directory to be the host’s project directory. Issuing them outside of the project directory will generate a warning followed by instructions on how to obtain an ID that would allow you to issue commands against a specific instance regardless of your current working directory.

Published inUncategorized