How do I automate snapshots on a weekly basis?

October 4, 2014 1.2k views

Hi there,

I was trying to explore the API and such and see what I can do to automate my snapshots, but I'm still a bit lost. For one, I cannot use the API to safely shutdown my droplet (have a support issue open but seems like they consider it "best effort") and I don't want to risk a power_off due to this being a production server and writing to a database frequently.

I'm open to scripts, other solutions, advice, etc.

Ultimately, I would like to implement the following as a close example:

1) Shutdown my droplet at 2 AM every Saturday night
2) Take a snapshot of the droplet above which would restart the server once its complete
3) Automate maintenance of those snapshots such as removing the oldest snapshot while only keeping 2 active snapshots, for example.

Does a solution like this exist so that I can automate my snapshots and maintain the images too? At the very least hoping to automate the snapshots and I can manually maintain the images.

Your help would be greatly appreciated, thank you in advance!

2 Answers

I'm interested to hear if of any solutions people are using for this. There aren't any public projects doing this that I know of that have set up the automation. Though, there are a lot of different ways to interact with the API that should make taking snapshots simple as well as API wrappers in different languages. Take a look at our projects page for a list.

One popular tool for using the API is Tugboat. Check out the tutorial here. You can snapshot a droplet as easily as running:

tugboat snapshot snapshot_name droplet_name

As the API commands need to be issues from outside of the droplet, you'll need to use some sort of local automation tool. If you have a Linux box or a Mac, there is always cron.

by Justin Ellingwood
Many tasks that you perform on a Linux server are repetitive and must be run at regular intervals. The cron and anacron utilities can be used to schedule tasks to run in the background at specific intervals. In this guide we will discuss the basics of how to use these two tools.

Second part of this tutorial shows how you can setup an automated snapshot capture using ruby script with crontab.

by Justin Ellingwood
There are plenty of options for how to backup your data on a VPS. DigitalOcean's snapshot feature is a way of backing up your data as an image. In this article, we will explain how to implement automated snapshots using a Ruby script and the cron scheduling utility.
Have another answer? Share your knowledge.