Guest User

Untitled

a guest
May 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'rubygems'
  4. require 'aws/s3'
  5.  
  6. S3_CREDENTIALS = File.expand_path(File.join('~', '.s3', 'auth.yml'))
  7. APP = 'darkblog'
  8. BUCKET = 's3.blog.darkhax.com'
  9.  
  10. def bundle
  11. `heroku bundles`.split(/\s/).first
  12. end
  13.  
  14. def destroy
  15. system("heroku bundles:destroy #{bundle}")
  16. end
  17.  
  18. def create
  19. system('heroku bundles:capture')
  20. end
  21.  
  22. def capturing?
  23. !`heroku bundles`.match('capturing').nil?
  24. end
  25.  
  26. def download
  27. `heroku bundles:download`.split(' ').last
  28. end
  29.  
  30. def key
  31. Time.now.strftime('%m-%d-%Y-%H-%M.tar.gz')
  32. end
  33.  
  34. def backup!
  35. destroy
  36. create
  37.  
  38. print 'Waiting for capture to finish...'
  39. while capturing?
  40. print '.'
  41. sleep(1)
  42. end
  43. print "done!\n"
  44.  
  45. AWS::S3::Base.establish_connection!(YAML.load_file(S3_CREDENTIALS))
  46. archive = download
  47. File.open(archive, 'rb') do |f|
  48. AWS::S3::S3Object.store("/backups/#{key}", f, BUCKET)
  49. end
  50. print "Done!\n"
  51. end
  52.  
  53. backup!
Add Comment
Please, Sign In to add comment