Automate volume snapshots on Digital Ocean & save money

Kumar Chetan Sharma
2 min readApr 17, 2024

This is not going to be a super long story. Digital Ocean doesn’t have a feature which allows one to automatically take snapshots of volumes. For uninformed or AWS nerds

Volumes are network-based block devices that provide additional data storage for Droplets. You can move them between Droplets and resize them at any time.

And AWS equivalent of a Droplet is EC2 or a compute instance. You would use a volume where your regular databases do not fit. For example storing profile images, videos and what not.

I assume that Digital Ocean doesn’t want to offer a scheduled snapshots because…you may need these snapshots hourly, daily or may not even need them. Your choice.

However, if you want to create snapshots, you can manually create one at any point of time. Or, subscribe to a paid service which will

  • cost you minimum US$ 19 and will
  • create daily snapshots for not more than 3 resources
  • and few more handy features

Or else, you can use Digital Ocean’s REST-ful APIs and automate this step. Digital Ocean’s Block Storage APIs allows you to

  • list all your volumes
  • list snapshots per volume
  • create snapshots for a volume
  • delete snapshots for a volume

And following above I created a simple cron job in node js which creates hourly snapshots for a volume. The example source code for this is available here at https://github.com/kumarldh/do-volume-backup-job. The job has two parts

  • Create snapshots every hour
  • Delete extra snapshots, cuz every snapshot costs

Thanks! The code is available under simple condition

Do whatever you want to do with this source code, just credit me and don’t sue me.

Thanks!

--

--

Kumar Chetan Sharma
Kumar Chetan Sharma

Written by Kumar Chetan Sharma

C0d3🐵 from 🇮🇳. selfTaught. 😨 of CS, Algos & DS. World famous 👨‍🍳 at home. Pro Level Pro-Crastinator. Man child. Dad of (✿◠‿◠)(◠‿◠✿)

No responses yet