Vagrant Snapshot Tutorial - Women Who Code.
52129
post-template-default,single,single-post,postid-52129,single-format-standard,qode-core-1.0.1,ajax_fade,page_not_loaded,,capri child-child-ver-1.0.0,capri-ver-1.6, vertical_menu_with_scroll,smooth_scroll,grid_1200,blog_installed,wpb-js-composer js-comp-ver-4.12.1,vc_responsive
 

Vagrant Snapshot Tutorial

Vagrant Snapshot Tutorial

Hi, here is a small tutorial on how to make Vagrant snapshots (Vagrant backups). Snapshot is a saved state of a system in a certain time point that allows you to return to that state in case you need it. This lets you experiment and try things and quickly restore back to a previous state.

Like in the case with operating systems, when you work with Vagrant and its virtual machines, it is a good practice to make snapshots to be able to go back in time later. You should always have a backup in case something goes wrong. Typical cases for using snapshots are:

  • You are about to experiment with your system or project
  • Unstable work of a system that you need to fix (reproduce and find bugs)
  • Before work with Chef, Puppet, etc. — make a snapshot before launching them and roll back after
  • Make a snapshot before manual testing and roll back to the clean DB state

In Vagrant, since v 1.8 you have a specific command for working with snapshots:
vagrant snapshot, which has 6 subcommands:

  • push
  • pop
  • save
  • restore
  • list
  • delete/li>

You use these commands from the VM folder of your local machine, like:
yourlocalmachine/vagrant/yourvirtualmachine$

Vagrant push and pop

Push and pop are used for quick switching between the states.
Workflow example:
vagrant snapshot push

vagrant ssh

vagrant snapshot pop

Here you do a snapshot with vagrant snapshot push, then enter your VM with vagrant ssh to work on your projest, and once you feel you need to roll back, use the vagrant snapsot pop. Vagrant deleteds your snapshot once you roll back to it, so if you want to save it, use vagrant snapsot pop --no-delete

vagrant snapshot push — creates a snapshot and saves it. This is a shorter version of vagrant snapshot save, that allows you to avoid naming a snapshot.
vagrant snapshot push — inversion of the vagrant snapshot push, it restores the pushed state
Options:

--[no-]provision — to force running (or not running ) provision while using push and pop, example:
vagrant snapshot push --no-provision
--no-delete — helps to prevent deleiting of your snapshot when you are rolling back to it (by default a snapshot gets deleted the moment you roll back to that point)

save and restore

save и restore are longer versions of push and pop.
WARNING: DON’T MIX USING push/pop WITH save/restore, they are unsafe to mix!
For instance, if you did push, proeed with pop, and not with restore!

Using save:
vagrant snapshot save [vm-name] NAME
Saves a new snapshot with the names of your VM and your snapshot.
Using restore:
vagrant snapshot restore [vm-name] NAME
Restores the named snapshot.
Options:
--[no-]provision — forces the provisioners to run (or prevent them from doing so).

Vagrant list

vagrant shapshot list — lists all your previously taken snapshots (if you have any) — oldest on top, newest at the bottom.

Vagrant delete

vagrant snapshot delete NAME — deletes a specified named snapshot

Some providers (such as with VirtualBox) require all «child» snapshots to be deleted first. Vagrant itself does not track «children», but if this is the case, be sure to delete the snapshots in the reverse order they were taken (delete newer, than older ones).

This command is typically much faster if the machine is halted prior to snapshotting. The deletion can also be done online with most providers.

Official manual:
Vagrant Snapshot

No Comments

Post a Comment