Guest User

Untitled

a guest
Jul 19th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.95 KB | None | 0 0
  1. namespace :db do
  2.   desc "Run the database backup"
  3.   task :backup do
  4.     on roles(:db) do
  5.       adhoc = false
  6.       backup_dir = fetch(:backup_dir)
  7.       release_timestamp = fetch(:release_timestamp)
  8.       adhoc = true unless release_timestamp
  9.       release_timestamp = env.timestamp.strftime("%Y%m%d%H%M%S") if adhoc
  10.       dump_path = "#{backup_dir}/#{release_timestamp}"
  11.       execute :mkdir, '-p', dump_path
  12.       puts fetch(:db_user)
  13.       puts fetch(:db_pass)
  14.       puts fetch(:db_name)
  15.     end
  16.   end
  17.  
  18.   desc "Get the database credentials from our config file"
  19.   task :get_creds do
  20.     on roles(:app) do
  21.       f = File.read("#{deploy_to}/config/#{fetch(:environment)}/config.json")
  22.       json = JSON.parse(f)
  23.       set(:db_user, json['db']['maintenance']['username'])
  24.       set(:db_pass, json['db']['maintenance']['password'])
  25.       set(:db_name, json['db']['maintenance']['database'])
  26.     end
  27.   end
  28.  
  29.   before 'db:backup', :get_creds
  30.  
  31. end
Advertisement
Add Comment
Please, Sign In to add comment