Skip to main content

Managing Snapshots

1. Creating Snapshot

Command Description Notes
vagrant snapshot save <name> Saves the current state of the VM as a snapshot with the given name Creates a new snapshot; use vagrant snapshot list to see all snapshots
vagrant snapshot save <name> --force Overwrites an existing snapshot with the same name Useful when updating a snapshot to reflect recent changes

Example: Creating a Snapshot

vagrant snapshot save production-ready
Note: Snapshots are stored locally in the Vagrant environment and are not shared across team members unless explicitly included in version control.

2. Restoring Snapshot

Command Description Notes
vagrant snapshot list List all snapshots for the current VM Shows snapshot names and timestamps
vagrant snapshot restore <name> Restore VM to a specific snapshot Reverts all changes made after the snapshot was taken
vagrant snapshot go <name> Alias for vagrant snapshot restore Same functionality as restore

Example: Restore to a specific snapshot

vagrant snapshot restore production-backup
Note: Restoring a snapshot will revert all disk changes made since the snapshot was created. This includes file system modifications, installed packages, and configuration changes.
Warning: This action is irreversible. Ensure you have a backup of any important data before restoring.

Snapshot Restoration Process

  • Run vagrant snapshot list to view available snapshots
  • Identify the snapshot name you want to restore to
  • Execute vagrant snapshot restore <name>
  • Vagrant will revert the VM to that snapshot state

3. Saving Named Snapshot

Command Description Options Notes
vagrant snapshot save Saves a named snapshot of the current state --force - Overwrite existing snapshot with same name
--global - Save snapshot globally (for all boxes)
Snapshot name must be unique within the current Vagrant environment

Example: Save a Named Snapshot

vagrant snapshot save production-deploy
Note: Snapshots are saved in the .vagrant/snapshots directory within your project folder.
Warning: Snapshots do not include changes made to the Vagrant box's disk image or any external storage.

4. Restoring Named Snapshot

Command Description Notes
vagrant snapshot list List all snapshots for the current VM Shows snapshot names and timestamps
vagrant snapshot restore <name> Restore VM to a named snapshot Reverts all changes made after the snapshot was taken

Example: Restore a Named Snapshot

vagrant snapshot restore production-backup
Note: Ensure the VM is not running before restoring a snapshot. Vagrant will automatically halt the VM if needed.

5. Listing Snapshots

Command Description Notes
vagrant snapshot list Lists all snapshots for the current VM Shows snapshot names and timestamps
vagrant snapshot list --machine-readable Lists snapshots in machine-readable JSON format Useful for scripting and automation

Example: Listing snapshots

$ vagrant snapshot list
default: Snapshot 1 (2026-04-01 10:30:00)
default: Snapshot 2 (2026-04-02 15:45:00)
default: Snapshot 3 (2026-04-03 09:15:00)
Note: Snapshots are only available for VMs managed by Vagrant. The output format may vary depending on the provider (VirtualBox, VMware, etc.).

6. Deleting Snapshot

Command Description Notes
vagrant snapshot delete <name> Deletes a specific snapshot by name Snapshot must exist, otherwise command fails
vagrant snapshot delete --all Deletes all snapshots for the current VM Use with caution as it removes all snapshot history

Example: Delete a specific snapshot

vagrant snapshot delete my-snapshot
Warning: Deleting a snapshot is irreversible and will remove all associated state data.
Note: Use vagrant snapshot list to view existing snapshots before deletion.

7. Using Snapshot Descriptions

Field Description Notes
description string Human-readable description of the snapshot

Example: Setting Snapshot Description

vagrant snapshot save default "production-deploy-2026-01-15"
Note: Descriptions are stored with the snapshot and can be used to identify snapshots in lists or logs.

8. Checking Snapshot Support

Feature Status Notes
Vagrant Version v2.4.0+ Snapshot support introduced in this version
Provider Support VirtualBox Full snapshot support available
Provider Support VMware Full snapshot support available
Provider Support Hyper-V Snapshot support limited to basic operations
Provider Support Libvirt Snapshot support experimental
Note: Snapshot functionality varies by provider. Always verify support in your environment.

9. Implementing Snapshot Best Practices

Snapshot Best Practices Overview

  • Regularly snapshot VMs before major changes or updates
  • Use descriptive names for snapshots to identify their purpose
  • Keep a minimal number of snapshots to avoid performance degradation
  • Automate snapshot creation using Vagrant provisioners or scripts
  • Ensure snapshots are backed up to external storage for disaster recovery
Best Practice Description Implementation
Descriptive Naming Use meaningful names for snapshots to identify their state vagrant snapshot save "before-upgrade"
Frequency Snapshot before major system updates or configuration changes Example: Pre-Update Snapshot vagrant snapshot save "pre-upgrade-2026"
Automation Use provisioners to automate snapshot creation Example: Snapshot Script
#!/bin/bash
vagrant snapshot save "automated-backup-$(date +%Y%m%d)"
Storage Store snapshots in a safe location for recovery Example: Backup Snapshot
vagrant snapshot save "backup-2026"
cp -r .vagrant/snapshots/ /backup/location/
Note: Vagrant snapshots are stored locally in the .vagrant/snapshots directory and should not be committed to version control.
Warning: Too many snapshots can lead to performance issues and disk space usage.

10. Managing Snapshot Storage

Storage Type Description Notes
Vagrant Box Storage Local storage of Vagrant boxes on the host machine Boxes are stored in ~/.vagrant.d/boxes/
Snapshot Storage Storage of VM snapshots managed by Vagrant Snapshots are stored in .vagrant/snapshots/ within the project directory
State Storage Current VM state and configuration Managed by Vagrant's internal state tracking, stored in .vagrant/

Example: Snapshot Storage Location

~/my-vagrant-project/.vagrant/snapshots/
Note: Vagrant snapshots are stored locally in the project directory and can be managed using vagrant snapshot commands.

Snapshot Storage Management

  • Snapshots are stored in .vagrant/snapshots/ directory
  • Each snapshot includes a unique identifier and metadata
  • Storage is managed automatically by Vagrant

Was this article helpful?