Created
February 20, 2018 13:41
-
-
Save qweluke/29659f17d61f15204b05e6b7138d67cd to your computer and use it in GitHub Desktop.
capistrano: dump database
This file contains hidden or 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
task :dump_db do | |
params = capture "cat #{deploy_to}/current/app/config/parameters.yml" | |
config = YAML.load(params) | |
backup_path = "#{fetch(:deploy_to)}/db_dumps" | |
run "mkdir -p #{backup_path}" | |
basename = 'database' | |
db_user = config['parameters']['database_user'] | |
db_pw = config['parameters']['database_password'] | |
db_name = config['parameters']['database_name'] | |
filename = "#{basename}_#{default_stage}_#{db_name}_#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.bz2" | |
run "mysqldump -u #{db_user} -p#{db_pw} #{db_name} | bzip2 -9 > #{backup_path}/#{filename}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment