I’m looking for a way to automate snapshots of my Droplets using doctl
. I want to make sure I have regular backups without manually creating snapshots every time.
Is there a way to schedule automatic snapshots with doctl
or through a simple script? Also, how can I manage old snapshots to avoid unnecessary storage costs?
Any guidance or examples would be much appreciated!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey! 👋
DigitalOcean offers automated backups which might be enough for your use-case:
For more advanced control you could also look into the SnapShooter service:
If you explicitly want to create snapshots yourself, you can indeed use the
doctl
CLI tool!First, run this command to manually create a snapshot for a Droplet:
This will create a snapshot with the current date in the name for easy tracking.
For more information, you can check the official documentation:
To automate this, create a cron job to run the command daily. Open the crontab editor:
Then, add this line to run the snapshot command every day at midnight:
Make sure your
doctl
is authenticated (doctl auth init
) and that your environment variables are properly set if using in scripts.To avoid storage bloat, you can delete snapshots older than, say, 7 days. Here’s a quick script for that:
You can check out the documentation for
doctl compute snapshot list
anddoctl compute snapshot delete
for more information:You can set this script on a weekly cron to clean up old snapshots!
Hope this helps!
- Bobby