Last active
January 15, 2018 21:11
-
-
Save jetchirag/2465e91eec87aff9b4ff032b647c388b to your computer and use it in GitHub Desktop.
Script to ensure (upto a level) backups are working
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 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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Directories which are checked are listed in variable dirList
"DIR_PATH" : DAYS