you are in: codestackercodes [RSS] → tag: rake [RSS]

task for database backup Delicious Email

another solutions:

http://blog.craigambrose.com/articles/2007/03/01/a-rake-task-for-database-backups
http://tiago.zusee.com/blog/2007/06/12/rake-task-para-backup-de-banco-de-dados-em-rails/
http://derenci.us/2007/7/backup-do-banco-com-rake

show/hide lines
   1  require 'ftools'
   2  require 'find'
   3  namespace :db do
   4    desc "Backup the database to a file. Options: DIR=base_dir RAILS_ENV=production COMPACT=true MAX=2"
   5    task :backup => [:environment] do
   6      datestamp = Time.now.strftime("%Y-%m-%d")
   7      hourstamp = Time.now.strftime("%H-%M-%S")
   8      base_path = ENV["DIR"] || "db"
   9      backup_base = File.join(base_path, 'backup')
  10      backup_file = File.join(backup_base, "#{RAILS_ENV}_#{datestamp}_#{hourstamp}_dump.sql")
  11      File.makedirs(backup_base)
  12      db_config = ActiveRecord::Base.configurations[RAILS_ENV]
  13      host = " -h #{db_config['host']} " if db_config['host'] and !db_config['socket']
  14  
  15      sh "mysqldump #{host} -u #{db_config['username']} -p#{db_config['password']} #{db_config['database']} > #{backup_file}"
  16      puts "Created backup: #{backup_file}"
  17      
  18      sh "bzip2 -z #{backup_file}" if ENV["COMPACT"] == "true" 
  19      puts "Compacted backup: #{backup_file}.bz2" if ENV["COMPACT"] == "true" 
  20      
  21      dir = Dir.new(backup_base)
  22      all_backups = dir.entries[2..-1].sort
  23      max_backups = ENV["MAX"].to_i || 5
  24      unwanted_backups = all_backups[max_backups..-2] || []
  25      for unwanted_backup in unwanted_backups
  26        FileUtils.rm_rf(File.join(backup_base, unwanted_backup))
  27        puts "- Deleted old backup: #{unwanted_backup}" 
  28      end
  29      puts "Deleted #{unwanted_backups.length} backups, #{all_backups.length - unwanted_backups.length} backups available"
  30    end
  31  end
created by leozera — 23 October 2008 — get a short url — tags: rails rake ruby task embed

rake tasks for gem dependencies Delicious Email

show/hide lines
   1  rake gems:install # Installs all required gems for this application
   2  rake gems:unpack # Unpacks the specified gem into vendor/gems
created by leozera — 07 September 2008 — get a short url — tags: rake ruby embed