Last active
June 28, 2018 06:22
-
-
Save ajinabraham/ad37bb5fad91b7f0a5c3576028efe064 to your computer and use it in GitHub Desktop.
Periodic Digital Ocean Snapshot is cheaper than Backups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import datetime | |
import digitalocean | |
TOKEN = "**" | |
SERVERS = {**: "**", **: "**"} | |
def snapshot_backup(): | |
manager = digitalocean.Manager(token=TOKEN) | |
my_droplets = manager.get_all_droplets() | |
snapshots = [] | |
tms = time.time() | |
tms_format = datetime.datetime.fromtimestamp(tms).strftime('%Y-%m-%d %H:%M:%S') | |
print("[{}] - Getting Current Snapshots".format(tms_format)) | |
# List All Droplets | |
for drop in my_droplets: | |
if drop.id in SERVERS.keys(): | |
snapshots += drop.get_snapshots() | |
print("[{}] - Deleting Current Snapshots".format(tms_format)) | |
try: | |
# Delete Current Snapshots of Droplets | |
for snapshot in snapshots: | |
snapshot.destroy() | |
except: | |
pass | |
print("[{}] - Creating new Snapshots".format(tms_format)) | |
# Create new Snapshots | |
for drop in my_droplets: | |
if drop.id in SERVERS.keys(): | |
drop.take_snapshot(SERVERS[drop.id]) | |
snapshot_backup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment