Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'yaml'
- require 'fileutils'
- desc "takes db backup and stores it to /var/backups/timestamp.sql with"
- task :db_backup => :environment do
- production = YAML.load(File.read(File.join(RAILS_ROOT, "config/database.yml")))['production']
- db = production['database']
- username = production['username']
- password = production['password']
- t = Time.now
- filepath = "/var/backups/"
- filename = "acnm_#{Time.now.strftime('%b_%d_%Y').downcase}.sql"
- FileUtils.cd(filepath)
- %x{mysqldump #{db} > #{filename} -u #{username} -p#{password}}
- puts "====================================================="
- if File.exists?(filename)
- %x{tar -czf #{filename + ".tar.gz"} #{filename}}
- FileUtils.rm(filename)
- puts "Database dump successfully created"
- else
- puts "ERRORS while creating database dump"
- end
- puts "====================================================="
- end
Add Comment
Please, Sign In to add comment