ruby postgres.rake
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby postgres.rake相关的知识,希望对你有一定的参考价值。
namespace :postgres do
desc 'Backup postgres database'
task :backup => :environment do
db_config = Rails.application.config.database_configuration[Rails.env]
backup_dir = '/home/deploy/backups'
outfile = "#{ backup_dir }/#{ Rails.env }_#{ DateTime.now.strftime("%Y%m%d_%H%M%S.sql.gz") }"
cmd = "pg_dump -h localhost -U #{ db_config['username'] } #{ db_config['database'] } | gzip -c > #{outfile}"
puts "Making database backup..."
system cmd
end
desc 'Restore postgres from an existing backup'
task :restore, [:backup] => [:environment] do |t, args|
db_config = Rails.application.config.database_configuration[Rails.env]
cmd = "psql -h localhost -U #{ db_config['username'] } #{ db_config['database'] } < #{ args[:backup] }"
puts cmd
end
end
以上是关于ruby postgres.rake的主要内容,如果未能解决你的问题,请参考以下文章
Ruby运算符
Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速
如何学习ruby?Ruby学习技巧分享
ruby Ruby脚本,看看是否用openssl编译了ruby
什么是ruby?
ruby和ruby ee