Module: MongoBacker::Actions

Includes:
Thor::Actions
Included in:
Cli
Defined in:
lib/mongo_backer/actions.rb

Instance Method Summary collapse

Instance Method Details

#ask_with_default(msg, default_value) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/mongo_backer/actions.rb', line 5

def ask_with_default (msg, default_value)
 answer = ask(msg + "(#{default_value})")
 
 if answer.nil? or answer.empty?
   answer = default_value
 end
 
 answer
end

#gzip_directory(dir) ⇒ Object



24
25
26
27
28
29
# File 'lib/mongo_backer/actions.rb', line 24

def gzip_directory(dir)
  zip_file = "#{dir}.tar.gz"
  run("tar -czf #{zip_file} #{dir}")
  
  zip_file
end

#list_backups(config) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/mongo_backer/actions.rb', line 40

def list_backups(config)
  manager = MongoBacker::S3Manager.new config
  backups = manager.find_all
  
  backups.each do |backup|
    say "#{backup.key} created at #{backup.last_modified}"
  end
  
end

#run_mongodump(config) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/mongo_backer/actions.rb', line 15

def run_mongodump(config)
  time = Time.new.strftime("%Y_%m_%d_%H-%M-%S")
  backup_dir = "#{Dir.tmpdir}/mongodump_#{time}"
  
  run("#{config.mongodump} -h #{config.host}:#{config.port} -o #{backup_dir}")
  
  backup_dir
end

#upload_to_s3(file, config) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/mongo_backer/actions.rb', line 31

def upload_to_s3(file, config)
  say "uploading backup to s3"

  manager = MongoBacker::S3Manager.new config
  manager.upload_file file
  
  say "finished uploading backup to s3"
end