Module: Dump

Extended by:
RailsRoot
Defined in:
lib/dump.rb,
lib/dump/env.rb,
lib/dump/assets.rb,
lib/dump/reader.rb,
lib/dump/writer.rb,
lib/dump/railtie.rb,
lib/dump/snapshot.rb,
lib/dump/env/filter.rb,
lib/dump/rails_root.rb,
lib/dump/continious_timeout.rb,
lib/dump/table_manipulation.rb

Overview

based on Timeout

Defined Under Namespace

Modules: Assets, ContiniousTimeout, Env, RailsRoot, TableManipulation Classes: Railtie, Reader, Snapshot, Writer

Class Method Summary collapse

Methods included from RailsRoot

rails_root

Class Method Details

.cleanup(options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dump.rb', line 62

def cleanup(options = {})
  unless options[:leave].nil? || /^\d+$/ =~ options[:leave] || options[:leave].downcase == 'none'
    fail 'LEAVE should be number or "none"'
  end

  to_delete = []

  all_dumps = Snapshot.list(options.merge(:all => true))
  to_delete.concat(all_dumps.select{ |dump| dump.ext != 'tgz' })

  dumps = Snapshot.list(options)
  leave = (options[:leave] || 5).to_i
  to_delete.concat(dumps[0, dumps.length - leave]) if dumps.length > leave

  to_delete.each do |dump|
    dump.lock do
      begin
        dump.path.unlink
        puts "Deleted #{dump.path}"
      rescue => e
        $stderr.puts "Can not delete #{dump.path}#{e}"
      end
    end
  end
end

.create(options = {}) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/dump.rb', line 42

def create(options = {})
  dump = Snapshot.new(options.merge(:dir => File.join(rails_root, 'dump')))

  Writer.create(dump.tmp_path)

  File.rename(dump.tmp_path, dump.tgz_path)
  puts File.basename(dump.tgz_path)
end

.restore(options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/dump.rb', line 51

def restore(options = {})
  dump = Snapshot.list(options).last

  if dump
    Reader.restore(dump.path)
  else
    $stderr.puts 'Avaliable versions:'
    $stderr.puts Snapshot.list
  end
end

.versions(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dump.rb', line 19

def versions(options = {})
  Snapshot.list(options).each do |dump|
    if Dump::Env[:show_size] || $stdout.tty?
      puts "#{dump.human_size.to_s.rjust(7)}\t#{dump}"
    else
      puts dump
    end
    begin
      case options[:summary].to_s.downcase[0, 1]
      when *%w[1 t y]
        puts Reader.summary(dump.path)
        puts
      when *%w[2 s]
        puts Reader.summary(dump.path, :schema => true)
        puts
      end
    rescue => e
      $stderr.puts "Error reading dump: #{e}"
      $stderr.puts
    end
  end
end