Guest User

Untitled

a guest
Feb 20th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. require 'yaml'
  2. require 'fileutils'
  3.  
  4. desc "takes db backup and stores it to /var/backups/timestamp.sql with"
  5. task :db_backup => :environment do
  6. production = YAML.load(File.read(File.join(RAILS_ROOT, "config/database.yml")))['production']
  7. db = production['database']
  8. username = production['username']
  9. password = production['password']
  10. t = Time.now
  11. filepath = "/var/backups/"
  12. filename = "acnm_#{Time.now.strftime('%b_%d_%Y').downcase}.sql"
  13. FileUtils.cd(filepath)
  14. %x{mysqldump #{db} > #{filename} -u #{username} -p#{password}}
  15. puts "====================================================="
  16. if File.exists?(filename)
  17. %x{tar -czf #{filename + ".tar.gz"} #{filename}}
  18. FileUtils.rm(filename)
  19. puts "Database dump successfully created"
  20. else
  21. puts "ERRORS while creating database dump"
  22. end
  23. puts "====================================================="
  24. end
Add Comment
Please, Sign In to add comment