forked from NARKOZ/hacker-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close NARKOZ#33
- Loading branch information
Showing
1 changed file
with
13 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,21 @@ | |
GMAIL_PASSWORD = ENV['GMAIL_PASSWORD'] | ||
|
||
gmail = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD) | ||
kumars_email = '[email protected]' | ||
|
||
DB_NAME_REGEX = /\S+_staging/ | ||
KEYWORDS_REGEX = /sorry|help|wrong/i | ||
|
||
gmail.inbox.find(:unread, from: '[email protected]').each do |email| | ||
if email.body[KEYWORDS_REGEX] | ||
# Restore DB and send a reply | ||
gmail.inbox.find(:unread, from: kumars_email).each do |email| | ||
if email.body[KEYWORDS_REGEX] && (db_name = email.body[DB_NAME_REGEX]) | ||
backup_file = "/home/backups/databases/#{db_name}-" + (Date.today - 1).strftime('%Y%m%d') + '.gz' | ||
abort 'ERROR: Backup file not found' unless File.exist?(backup_file) | ||
|
||
# Restore DB | ||
`gunzip -c #{backup_file} | psql #{db_name}` | ||
|
||
# Mark as read, add label and reply | ||
email.read! | ||
email.label('Database fixes') | ||
reply = create_reply(email.subject) | ||
gmail.deliver(reply) | ||
|
@@ -23,7 +32,7 @@ | |
|
||
def create_reply(subject) | ||
gmail.compose do | ||
to "[email protected]" | ||
to kumars_email | ||
subject "RE: #{subject}" | ||
body "No problem. I've fixed it. \n\n Please be careful next time." | ||
end | ||
|