Snapshot
A snapshot is a point-in-time copy of a volume or instance state that captures all data as it existed at the moment of creation, enabling backup, recovery, and cloning operations.
What is a Snapshot in cloud hosting?
A snapshot is a point-in-time copy of a volume (virtual disk) or instance (virtual machine) state. When you create a snapshot, the cloud platform captures all data exactly as it exists at that moment. The original volume or instance continues operating normally while the snapshot preserves that frozen state.
Snapshots differ from continuous backups. A backup typically involves copying data to a separate location on a schedule. A snapshot captures an instant record of the storage blocks in use. Cloud platforms store snapshots efficiently by recording only the blocks that contain data, rather than copying empty space.
Related Terms
- Volume: A virtual disk attached to an instance, such as a 100GB block storage volume holding your database files. Snapshots capture the complete state of a volume.
- Instance: A virtual machine running in the cloud, such as a web server or database host. Instance snapshots capture both the root disk and the running configuration.
- Image: A bootable template used to launch new instances, such as an Ubuntu 22.04 base image. Snapshots can be converted into images to create reusable templates.
Why Snapshots Exist
Without snapshots, protecting data in cloud environments would require stopping instances, copying entire disks, and storing duplicate data. This process would cause downtime and consume excessive storage space.
Snapshots solve several problems:
- Data protection without downtime: You can capture a volume's state while it remains attached and in use
- Efficient storage: Only the actual data blocks are stored, not empty space or unchanged blocks from previous snapshots
- Fast recovery: Restoring a snapshot takes minutes, not hours
- Cloning capability: You can create new volumes or instances from snapshots without affecting the original
Before snapshots existed, administrators had to schedule maintenance windows to perform backups. A database administrator might need to stop the database, copy the entire disk, then restart the database. With snapshots, the same backup takes seconds and causes no interruption.
What Do Snapshots Actually Do?
- Capture block-level data: Record the exact state of every storage block at the moment of creation
- Enable point-in-time recovery: Restore a volume or instance to the exact state captured in the snapshot
- Create new volumes: Launch new volumes pre-populated with data from the snapshot
- Generate bootable images: Convert instance snapshots into images that can launch new instances
- Preserve data before changes: Provide a rollback point before software updates, configuration changes, or migrations
- Support geographic replication: Copy snapshots to different regions for disaster recovery
When Would I Use a Snapshot?
Before making changes: Create a snapshot before installing software updates, modifying configurations, or running database migrations. If something goes wrong, you can restore the previous state.
For regular backups: Schedule daily or weekly snapshots of critical volumes. If data corruption occurs or files are accidentally deleted, you can recover from the most recent snapshot.
When cloning environments: Create a snapshot of your production database, then launch a new volume from that snapshot for testing. Your test environment starts with real data without affecting production.
Before instance termination: If you might need an instance again, create a snapshot before deleting it. You can launch a new instance from the snapshot later.
For disaster recovery: Copy snapshots to a different region. If the primary region becomes unavailable, you can restore volumes and instances in the backup region.
When Would I NOT Use a Snapshot?
For application-level backups: Snapshots capture disk blocks, not application state. A database snapshot taken while transactions are in progress may contain inconsistent data. Use your database's native backup tools for consistent application backups, then snapshot the resulting backup files.
As your only backup method: Snapshots typically reside in the same storage system as the original data. If that storage system fails, both the volume and its snapshots could be lost. Copy snapshots to separate storage or another region for true disaster recovery.
For large, rapidly changing data: Snapshots work best for data that changes incrementally. If your workload rewrites most data frequently, each snapshot will be nearly as large as the original volume, reducing storage efficiency.
When storage costs matter significantly: Snapshots consume storage space. Keeping many snapshots of large volumes can become expensive. Establish a retention policy to delete old snapshots automatically.
Real-World Example
Company A operates an e-commerce platform with a 500GB PostgreSQL database. Their operations include:
Daily backup strategy: At 2 AM each night, their automation:
- Runs
pg_start_backup()to ensure database consistency - Creates a snapshot of the database volume
- Runs
pg_stop_backup()to resume normal operations - Deletes snapshots older than 30 days
Pre-deployment protection: Before each code deployment:
- Create snapshots of all application server volumes
- Deploy the new code
- If tests fail, restore volumes from the pre-deployment snapshots
- If tests pass, delete the temporary snapshots after 24 hours
Testing with production data: Monthly, the QA team:
- Creates a snapshot of the production database volume
- Launches a new volume from that snapshot
- Attaches the new volume to a test instance
- Runs tests against real data without affecting production
- Deletes the test volume when finished
This approach provides recovery points every 24 hours, rollback capability for deployments, and realistic test data without manual copying.
Frequently Asked Questions
Can I use a snapshot while the original volume is still running? Yes. Snapshots capture the data at a specific instant without requiring you to detach or stop the volume. However, for databases and other applications with in-memory state, you should use application-level tools to ensure consistency before creating the snapshot.
How long does it take to create a snapshot? Creating a snapshot typically takes seconds to minutes, regardless of volume size. The cloud platform records which blocks to capture almost instantly. The actual data copy may continue in the background, but you can resume using the volume immediately.
What happens to my snapshots if I delete the original volume? Snapshots remain available after you delete their source volume. You can restore a new volume from the snapshot at any time. Snapshots are independent objects once created, though your cloud platform may store them more efficiently when the original volume exists.
How much storage space does a snapshot use? The first snapshot of a volume uses space proportional to the actual data stored, not the volume's total size. A 500GB volume containing 100GB of data produces roughly a 100GB snapshot. Subsequent snapshots store only the blocks that changed, which is often much smaller.
Can I share a snapshot with another account or project? Most cloud platforms allow sharing snapshots between accounts or projects. You can also copy snapshots to different regions. Check your platform's documentation for specific sharing and copying capabilities, as permissions and procedures vary.
Summary
- A snapshot is a point-in-time copy of a volume or instance state that captures all data at the moment of creation
- Snapshots enable backup, recovery, and cloning without causing downtime or stopping the source volume
- Use snapshots before making changes to preserve a rollback point, for regular backups, and to clone data for testing
- Snapshots are not a replacement for application-level backups when data consistency matters
- Implement retention policies to manage storage costs as snapshots accumulate over time
