File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 99GMAIL_PASSWORD = ENV [ 'GMAIL_PASSWORD' ]
1010
1111gmail = Gmail . connect ( GMAIL_USERNAME , GMAIL_PASSWORD )
12+ kumars_email = '[email protected] ' 1213
14+ DB_NAME_REGEX = /\S +_staging/
1315KEYWORDS_REGEX = /sorry|help|wrong/i
1416
15- gmail . inbox . find ( :unread , from :
'[email protected] ' ) . each do |
email |
16- if email . body [ KEYWORDS_REGEX ]
17- # Restore DB and send a reply
17+ gmail . inbox . find ( :unread , from : kumars_email ) . each do |email |
18+ if email . body [ KEYWORDS_REGEX ] && ( db_name = email . body [ DB_NAME_REGEX ] )
19+ backup_file = "/home/backups/databases/#{ db_name } -" + ( Date . today - 1 ) . strftime ( '%Y%m%d' ) + '.gz'
20+ abort 'ERROR: Backup file not found' unless File . exist? ( backup_file )
21+
22+ # Restore DB
23+ `gunzip -c #{ backup_file } | psql #{ db_name } `
24+
25+ # Mark as read, add label and reply
26+ email . read!
1827 email . label ( 'Database fixes' )
1928 reply = create_reply ( email . subject )
2029 gmail . deliver ( reply )
2332
2433def create_reply ( subject )
2534 gmail . compose do
26- 35+ to kumars_email
2736 subject "RE: #{ subject } "
2837 body "No problem. I've fixed it. \n \n Please be careful next time."
2938 end
You can’t perform that action at this time.
0 commit comments