Skip to content

Instantly share code, notes, and snippets.

@peterkodermac
Created April 28, 2020 07:33
Show Gist options
  • Save peterkodermac/d9f5bbeeb8b70cfae8a3abb3d4e67799 to your computer and use it in GitHub Desktop.
Save peterkodermac/d9f5bbeeb8b70cfae8a3abb3d4e67799 to your computer and use it in GitHub Desktop.
Digital ocean create snapshots - backups
import digitalocean
import random
api_key = 'REPLACE_API'
manager = digitalocean.Manager(token=api_key)
my_droplets = manager.get_all_droplets()
zmayDroplet=my_droplets[0]
zmayDroplet.take_snapshot('snapshot-'+str(random.randint(1,10000))) #this makes a snapshot
print "snapshot made"
snapshots=manager.get_all_snapshots()
if len(snapshots)>1:
destroySnapshot=digitalocean.Snapshot.get_object(api_key, snapshots[0].id)
destroySnapshot.destroy()
else:
print "no snapshots to delete"
@peterkodermac
Copy link
Author

peterkodermac commented Apr 28, 2020

Thanks a lot code is working perfect..i need one more help
I am trying to create Loadbalancer from lastr two days but i can't able to do ,I am trying below code but no luck can you guide me how to create LoadBalancer and how can we add and remove the droplets from `LB?
import digitalocean
lb = digitalocean.LoadBalancer(token="api_token",
name= 'test',
region= 'BLR1',
forwarding_rules= ["entry_protocol::http"])

lb.create()
print('LB is Created')```

sorry but I have no experience with loadbalancer whatsoever. Maybe there's something useful at the documentation of the library which you import at the beginning of the script.

@GOPIPACHA
Copy link

Ok thanks no worries

@GOPIPACHA
Copy link

GOPIPACHA commented May 9, 2020

Hey Hi ,

Hiw are you are doing

I just wanted to know can we create a snapshot basesd on the tag name or any otherway apart from position of droplet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment