DEV Community

Cover image for Exploring Vagrant: Snapshots - Part 6
Syam SV
Syam SV

Posted on

Exploring Vagrant: Snapshots - Part 6

A snapshot is a saved state of a virtual machine at a specific point in time. This allows you to capture the current state of the virtual machine and return to it later if needed. Snapshots are useful for various scenarios, such as testing different configurations, rolling back changes, and isolating development environments.

Creating a Snapshot

To create a snapshot of a running virtual machine, use the vagrant snapshot save command followed by the snapshot name:

vagrant snapshot save <VM Name> <Snapshot Name>
Enter fullscreen mode Exit fullscreen mode

Example :

vagrant snapshot save my-vm snapshot1
Enter fullscreen mode Exit fullscreen mode

Vagrant snapshots invoke the "snapshots" method of the provider. In the case of using Vagrant snapshot with VirtualBox, it triggers VirtualBox's snapshot functionality and the snapshots will be stored in the same location where the virtual machine was created.

Listing Snapshots

To list all the snapshots associated with a virtual machine, use the vagrant snapshot list
command:

vagrant snapshot list
Enter fullscreen mode Exit fullscreen mode

or to list snapshots of a specific VM

vagrant snapshot list <VM Name>
Enter fullscreen mode Exit fullscreen mode

Roll Back or Restoring a Snapshot

You can roll back a virtual machine to a snapshot by restoring it. This is particularly useful when you want to revert to a known state before making changes. To restore a virtual machine to a specific snapshot, use the vagrant snapshot restore command.

vagrant snapshot restore <VM Name> <Snapshot Name>
Enter fullscreen mode Exit fullscreen mode

Example:

vagrant snapshot restore default snap1 
Enter fullscreen mode Exit fullscreen mode

Deleting a Snapshot

To delete a snapshot, use the vagrant snapshot delete command:

vagrant snapshot delete <VM Name> <Snapshot Name>
Enter fullscreen mode Exit fullscreen mode

Example :

vagrant snapshot delete default snap1
Enter fullscreen mode Exit fullscreen mode

Remember that snapshots consume disk space, and managing them is important to avoid excessive disk usage. Also, snapshots might not capture every aspect of the system, such as network configurations, so be aware of potential limitations.

Top comments (0)