vagrant-snapshot
Manage virtual machine snapshots
TLDR
Take a snapshot of the machine (running or stopped)
Restore a snapshot and start the machine
Restore a snapshot without starting the machine
Delete a snapshot
List available snapshots of the machine
SYNOPSIS
vagrant snapshot subcommand [machine-name] [args] [options]
Subcommands:
vagrant snapshot save [machine-name] name
vagrant snapshot restore [machine-name] name
vagrant snapshot list [machine-name]
vagrant snapshot delete [machine-name] name
PARAMETERS
subcommand
Specifies the action to perform: save, restore, list, or delete.
machine-name
Optional. The name of the specific Vagrant machine within the multi-machine environment to apply the command to. If omitted, the command typically applies to the primary or only machine.
name
Required for save, restore, and delete subcommands. A unique name to identify the snapshot.
--provider PROVIDER
Restricts the operation to a specific virtualization provider (e.g., virtualbox, vmware_fusion). Useful in multi-provider environments.
--force
For save, overwrites an existing snapshot with the same name. For restore, forces the restoration even if the VM's state is considered 'dirty' or not clean.
--provision
For restore, runs configured provisioners after restoring the snapshot. This ensures the VM is brought up to date after reverting its state.
--no-provision
For restore, prevents provisioners from running after the snapshot is restored. Useful for quick reverts without additional configuration steps.
--box BOX_NAME
For list and delete, specifies that snapshots should be managed for a Vagrant box, not a specific machine. Useful for cleaning up space or managing shared box snapshots.
DESCRIPTION
The `vagrant snapshot` command provides a powerful way to manage the state of your development virtual machines. It allows users to save the current state of a running or halted VM, restore a VM to a previously saved state, list all existing snapshots for a VM, or delete unneeded snapshots. This functionality is crucial for developers who need to quickly revert to a known good state, experiment with changes without fear of permanent damage, or share specific VM states within a team. Snapshots capture the entire disk and memory state of the VM at a given point, making them invaluable for debugging complex issues or setting up consistent test environments. It leverages the underlying virtualization provider's snapshot capabilities (e.g., VirtualBox, VMware) to perform these operations.
CAVEATS
Snapshots can consume significant disk space, as they store the full state of the VM's disk and sometimes memory. Frequent or numerous snapshots can lead to large disk usage.
Not all virtualization providers offer the same level of snapshot functionality, and some may have limitations or performance implications.
While useful for development, snapshots are generally not a robust solution for production backups or continuous integration environments; they are best suited for local development workflow management.
Restoring a snapshot effectively rewinds the VM's state. Any data or changes made after the snapshot was taken will be lost unless backed up externally.
SNAPSHOT NAMING BEST PRACTICES
When saving snapshots, it's highly recommended to use descriptive names that indicate the state of the VM, such as 'initial_os_install', 'after_db_setup', or 'pre_feature_x_branch_merge'. This makes it much easier to identify and restore the correct state later on.
COMMON USE CASES
Beyond simple rollback, `vagrant snapshot` is invaluable for:
- Debugging: Revert to a state just before a bug occurred to reproduce and debug.
- Feature Branching: Take a snapshot before switching to a new feature branch, allowing a quick return to the previous environment.
- Testing: Test multiple configurations or software versions by restoring to different baseline snapshots.
HISTORY
The `vagrant snapshot` functionality was integrated into Vagrant as a core feature to address the common developer need for quick state management and rollback capabilities. Vagrant, created by Mitchell Hashimoto, aims to provide an easy-to-use layer for managing virtual development environments. As virtualization technology advanced and became more accessible, the ability to snapshot a VM became a fundamental requirement for efficient iterative development and debugging workflows. This command leverages the native snapshot features of underlying hypervisors like VirtualBox and VMware, abstracting away their specific commands into a unified Vagrant interface.