Class: Backy::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



6
7
8
9
10
# File 'lib/backy/cli.rb', line 6

def initialize(*args)
  Logger.log("Initializing Backy CLI...")
  super
  Backy.setup
end

Instance Method Details

#downloadObject



37
38
39
40
41
42
# File 'lib/backy/cli.rb', line 37

def download
  file_name = options[:file]
  validate_file!(file_name, should_exist: false)
  load_from_s3_if_missing(file_name)
  Logger.success("File downloaded from S3.")
end

#dumpObject



13
14
15
16
# File 'lib/backy/cli.rb', line 13

def dump
  Backy::PgDump.new.call
  Logger.success("Database dumped successfully.")
end

#listObject



45
46
47
48
49
# File 'lib/backy/cli.rb', line 45

def list
  list = Backy::List.new.call
  list.each { |item| say "#{item.local? ? "local" : "     "} #{item.remote? ? "remote" : "      "} : #{item.dump_file}", :yellow }
  say_instructions_if_any(list)
end

#pushObject



19
20
21
22
23
24
# File 'lib/backy/cli.rb', line 19

def push
  file_name = Backy::PgDump.new.call
  save_to_s3(file_name)
  File.delete(file_name) if File.exist?(file_name)
  Logger.success("Dump pushed to S3 and local file deleted.")
end

#restoreObject



53
54
55
56
57
# File 'lib/backy/cli.rb', line 53

def restore
  file_name = find_file_for_restore(options[:file])
  pg_restore(load_from_s3_if_missing(file_name)) if file_name
  Logger.success("Database restored from #{file_name}.")
end

#uploadObject



28
29
30
31
32
33
# File 'lib/backy/cli.rb', line 28

def upload
  file_name = options[:file]
  validate_file!(file_name)
  save_to_s3(file_name)
  Logger.success("File uploaded to S3.")
end