Snapshot automation for droplets and volumes in DigitalOcean Cloud platform
Digtalocean Automate Snapshot for Droplet and Volumes[edit]
Reference https://pypi.org/project/goutte/
Issue - For Python 3.7 on Centos 6
Reference - https://benad.me/blog/2018/07/17/python-3.7-on-centos-6/
Genrate Api KEY for digital Ocean via
https://www.easydeploy.cloud/blog/automate-droplet-snapshot-digitalocean/?unapproved=39&moderation-hash=6864fe13b1a4810007aa7067bbdca7db#comment-39
only first 2 Step to be followed
Finally on Live Server For example , at mail.blsinternational.net
goutte /usr/local/etc/goutte.toml 36c095a48c01428e14b1a38c3ddce5cb57d65df42cb1d727e59a22735b1a6236 --only snapshot
And file /usr/local/etc/goutte.toml
retention = 2 # Number of backups to keep per droplet/volume [droplets] names = [ # Array of droplets you want to snapshot 'mail.blsinternational.net', ] [volumes] names = [ # Array of volumes you want to snapshot 'bls-zimbra-store-01', ]
And Crontab Entry is
0 17 * * * goutte /usr/local/etc/goutte.toml 36c095a48c01428e14b1a38c3ddce5cb57d65df42cb1d727e59a22735b1a6236 --only snapshot > /dev/null
Deletion of Snapshots automatically keeping last 2 old Snapshots
Please install doctl via https://github.com/digitalocean/doctl
Create the following script
[root@mail ~]# cat /root/scripts/delete-old-snapshot.sh
#!/bin/bash
doctl compute snapshot list | grep goutte | head -n2 | awk '{ print $1 }' | \
while read i
do
echo "$i"
doctl compute snapshot delete -f $i
done
As all the snapshot of BLS international starts with goutte , we have used the logic of grepping this key word
In Crontab keep the time as 1 hour after the creation script has executed
0 18 * * * /root/scripts/delete-old-snapshot.sh >/dev/null 2>&1
Keep checking if it working fine periodically . Snapshots are costly so you should not have snapshots for which customer is not paying .