Class: WpBackup::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/wp_backup/cli.rb

Instance Method Summary collapse

Instance Method Details

#backupObject



9
10
11
12
13
# File 'lib/wp_backup/cli.rb', line 9

def backup
  config = Config.new(options[:config_file])
  key = Backup.new(config).create(!options[:site_only], !options[:db_only])
  puts "Backed up to #{key}"
end

#cleanupObject



28
29
30
31
32
33
34
35
36
# File 'lib/wp_backup/cli.rb', line 28

def cleanup
  config = Config.new(options[:config_file])
  keep = options[:keep]
  timestamps = {}
  config.s3.keys.each { |k| timestamps[Time.parse(k, "%Y%m%d%H%M%S")] = k }
  remove = timestamps.keys.sort.reverse.slice(keep.to_i, timestamps.length)
  timestamps.keep_if { |k,v| remove.include?(k) }
  config.s3.delete_keys(timestamps.values)
end

#create_config(file) ⇒ Object



46
47
48
# File 'lib/wp_backup/cli.rb', line 46

def create_config(file)
  Config.write_sample(file)
end

#listObject



17
18
19
20
21
22
23
# File 'lib/wp_backup/cli.rb', line 17

def list
  config = Config.new(options[:config_file])
  keys = config.s3.keys
  puts "Found #{keys.count} versions:"
  puts "========================"
  keys.each { |k| puts k }
end

#restore(key) ⇒ Object



40
41
42
43
# File 'lib/wp_backup/cli.rb', line 40

def restore(key)
  config = Config.new(options[:config_file])
  Backup.new(config).restore(key)
end