How’s your backup strategy? You can protect your cloud assets from disaster by making regular backups. Here’s how to use DigitalOcean’s two imaging systems, Backups and Snapshots.
What’s The Difference?
Backups and Snapshots both produce a complete disk image of your droplet at a particular point in time. You can restore the droplet’s state using the image. DigitalOcean also lets you spin up a new droplet with the backup or snapshot image as its base.
The difference lies in how the image is created. “Backups” is a fully-managed automated system. Backups are enabled on a per-droplet basis. When active, DigitalOcean will create a disk image each week. The backup will be retained for four weeks, so you’ll have four different recovery options.
Backups add another 20% to the monthly cost of your droplet. They’re stored in the same datacentre as your droplet, so it’s plausible – although perhaps improbable – that a datacentre-wide outage or natural disaster could prevent you using your backups.
Snapshots are on-demand images. You create them manually, using the Control Panel or the API. Once created, snapshots persist in your account indefinitely, until you explicitly delete them.
Snapshots are billed based on their size. You’ll pay $0.05/GiB per month. Snapshots are created in the same datacentre as your droplet. You can make snapshots available in other datacentre regions on a per-snapshot basis.
Unlike backups, snapshots aren’t limited to droplets. You can also create snapshots of your Block Storage Volumes. You should consider periodically snapshotting your volumes as they won’t be included in droplet snapshots or backups.
Setting Up Droplet Backups
Let’s look at setting up automated droplet backups first.
Login to your Digital Control Panel. Click any droplet on the homepage. Then, on the droplet details page, click the “Backups” link in the sidebar. You’ll see an “Enable Backups” button. Click the button to activate backups.
DigitalOcean automatically allocates you a weekly backup window which you can’t change or customise. The page will show you what your backup schedule is; until your schedule is run, no backups will be available for your droplet.
You can automate backup setup by using Doctl, DigitalOcean’s command-line client. Once you’re authenticated, run
doctl compute droplet list to get the list of droplets in your account. Note down the ID of the droplet you want to configure.
Next, setup backups for the droplet:
doctl compute droplet-action enable-backups <droplet-id>
Once backups have been created, you can list them using another command:
doctl compute droplet backups <droplet-id>
Restoring a Backup
You can view your four retained backups at the bottom of a droplet’s Backups page. Click the “More” button to see the available options.
You can restore your droplet by clicking “Restore Droplet” and acknowledging the confirmation prompt. This will overwrite your current droplet with the contents of the backup.
The “Create Droplet” option gives you another recovery strategy. This will let you configure a new droplet using the backup as its initial image. You’ll be taken to the droplet creation page to choose the hardware plan for your new droplet.
Finally, you can convert backups into snapshots. This lets you keep a backup indefinitely, beyond the end of the default monthly retention period. You can also use snapshots to transfer backup data into a new datacentre region.
To manage snapshots in the web interface, select a droplet and click the “Snapshots” link in its sidebar.
You create new snapshots using the controls at the top of the page. Give the snapshot a name and click “Take live snapshot”. This will capture the droplet without powering it off. If you need to guarantee data consistency, you should shutdown the droplet before taking the snapshot.
Snapshot creation takes up to 1 minute per GB of data used by your droplet. The snapshot will show up under “Droplet snapshots” when the process completes.
To snapshot a volume, click the Volumes link in the left sidebar. Click the “More” button next to any of your volumes. Press “Take snapshot” and give your snapshot a name. Volume snapshots require a similar creation time to droplet snapshots.
You can access all your droplet and volume snapshots from the “Images” link in the sidebar. Use the “Droplets” and “Volumes” tabs to see your snapshots.
The “More” menu lets you create a droplet from the snapshot, restore the droplet (or volume) using the snapshot, or transfer the snapshot into another region. The latter option lets you subsequently create a new droplet in a different datacentre that uses the snapshot as its base image.
You can orchestrate snapshot actions using Doctl. Here are some helpful commands when working with snapshots:
# Get all snapshots stored for a droplet doctl compute droplet snapshots <droplet-id> # Create a snapshot of a droplet doctl compute droplet-action snapshot <droplet-id> # Create a snapshot of a volume doctl compute volume snapshot <volume-id> # List all snapshots in your account doctl compute snapshot list # Delete a snapshot doctl compute snapshot delete <snapshot-id>
compute droplet list,
compute volume list and
compute snapshot list commands to get the resource IDs to supply to the snapshot commands shown above.
Backing Up Other DigitalOcean Resources
Backups are only for droplets; Snapshots are for droplets and volumes. You can’t use them with any other DigitalOcean resource type.
You should consider how you’ll backup your other DigitalOcean data. The platform’s managed services – such as Managed Databases and Spaces object storage – do have integrated backups within DigitalOcean’s infrastructure. You may want to manually backup to another cloud provider in the interest of ensuring redundancy.
DigitalOcean Backups are a set-it-and-forget-it approach to backups which should “just work” for most light workloads. However, the weekly schedule and same-datacentre storage won’t work for anything business-critical. If that’s the case, you should consider periodic snapshots or a custom backup system.
Snapshots are ideal when you’re about to make a major droplet configuration change. You can snapshot your machine to give you a recovery option in the event of failure. The portability of snapshots lets you move data between DigitalOcean regions without having to manually transfer anything.