Skip to content

Instantly share code, notes, and snippets.

@jetchirag
Last active January 15, 2018 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jetchirag/2465e91eec87aff9b4ff032b647c388b to your computer and use it in GitHub Desktop.
Save jetchirag/2465e91eec87aff9b4ff032b647c388b to your computer and use it in GitHub Desktop.
Script to ensure (upto a level) backups are working
import sendgrid
import os
import time
from sendgrid.helpers.mail import *
#import rotate
# Declare paths below
dirList = {
"/home/dir1":31,
"/home/dir2":4
}
# Declare paths above
faultyDir = {}
curTime = time.time()
for dir in dirList:
maxTime = dirList[dir]
dirTime = os.stat(dir).st_mtime
lastUpdate = int(curTime - dirTime) / 86400
if lastUpdate > maxTime:
faultyDir[dir] = lastUpdate
message = '<html><body>'
message += "Below are directories that have not been updated recently:<br><br>"
for fault in faultyDir:
message += fault + " : " + str(faultyDir[fault]) + " days<br><br>"
message += "<br><br>"
message += '</body></html>'
APIKEY=""
sg = sendgrid.SendGridAPIClient(apikey=APIKEY)
from_email = Email("")
to_email = Email("")
subject = "BACKXX Daily Report"
content = Content("text/html", message)
mail = Mail(from_email, subject, to_email, content)
sg.client.mail.send.post(request_body=mail.get())
@jetchirag
Copy link
Author

jetchirag commented Jan 15, 2018

Directories which are checked are listed in variable dirList

"DIR_PATH" : DAYS

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