Updated kumar_asshole.py to restore DB
This commit is contained in:
parent
01e916f59c
commit
7fe268bcb1
|
|
@ -3,9 +3,13 @@
|
|||
import gmail
|
||||
import sys
|
||||
import re
|
||||
import os
|
||||
from datetime import timedelta
|
||||
import datetime
|
||||
|
||||
GMAIL_USERNAME = ENV['GMAIL_USERNAME']
|
||||
GMAIL_PASSWORD = ENV['GMAIL_PASSWORD']
|
||||
|
||||
GMAIL_USERNAME = os.environ['GMAIL_USERNAME']
|
||||
GMAIL_PASSWORD = os.environ['GMAIL_PASSWORD']
|
||||
|
||||
g = gmail.login(GMAIL_USERNAME, GMAIL_PASSWORD)
|
||||
|
||||
|
|
@ -14,9 +18,21 @@ if not g.logged_in:
|
|||
|
||||
msgs = g.inbox().mail(sender="kumar.a@example.com", unread=True, prefetch=True)
|
||||
|
||||
pattern = re.compile("\bsorry\b | \bhelp\b | \bwrong\b ", flags=re.I)
|
||||
pattern = r'\bhelp\b|\bwrong\b|\bsorry\b'
|
||||
db_pattern = r'\S+_staging'
|
||||
|
||||
for msg in msgs:
|
||||
if pattern.match(msg.body):
|
||||
msg.label("Database fixes")
|
||||
msg.reply("No problem. I've fixed it. \n\n Please be careful next time.")
|
||||
if re.search(pattern, msg, flags=re.I):
|
||||
db_name = re.search(db_pattern, msg, flags=re.I)
|
||||
if db_name:
|
||||
dt_today = datetime.date.today()
|
||||
dt_lastday = (dt_today - timedelta(days=1)).strftime ("%Y%m%d")
|
||||
backup_file = '/home/backups/databases/%s-.gz'%(dt_lastday)
|
||||
if os.path.isfile(backup_file):
|
||||
exec_string = 'gunzip -c %s | psql %s'%(backup_file, db_name)
|
||||
os.system(exec_string)
|
||||
msg.label("Database fixes")
|
||||
msg.reply("No problem. I've fixed it. \n\n Please be careful next time.")
|
||||
else:
|
||||
print 'ERROR: Backup file not found'
|
||||
exit(1)
|
||||
|
|
|
|||
Loading…
Reference in New Issue