Class: DataExporter::CLI

Inherits:
Thor
  • Object
show all
Includes:
Actions
Defined in:
lib/data_exporter/cli.rb

Instance Method Summary collapse

Methods included from Actions

#compress, #config, #decrypt, #encrypt, #expand, #export, #find_last_backup, #find_last_s3_backup, #find_last_sftp_backup, #glob_escape, #unarchive, #unpack

Instance Method Details

#export_taskObject

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/data_exporter/cli.rb', line 45

def export_task
  config.load(options.merge(:mysql_required => !options[:archive_dir]))
  raise ArgumentError, '--csv required for --archive-dir' if options[:archive_dir] && !config.csv_enabled?

  local_encrypted_archive_name = File.join(config.export_dir, encrypted_export_archive_name)
  log "creating #{local_encrypted_archive_name}"
  export(config.backup_key, local_encrypted_archive_name, options[:archive_dir])

  begin
    upload(local_encrypted_archive_name, config.backup_dir)
  ensure
    unless options[:preserve]
      log "removing #{local_encrypted_archive_name}"
      FileUtils.rm(local_encrypted_archive_name)
    end
  end
end

#status_taskObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/data_exporter/cli.rb', line 66

def status_task
  config.load(options)

  remote_backup = find_last_backup(config.backup_prefix, backup_suffix, config.backup_dir)

  abort no_backups_message unless remote_backup
  log("last backup %s at %s (%s)" % [remote_backup.name, Time.at(remote_backup.mtime).utc.iso8601, bytes(remote_backup.size)])

  update_redis_counters(remote_backup, options[:redis_key_prefix]) if options[:redis_key_prefix]
end

#unpack_taskObject



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

def unpack_task
  config.load(options.merge(:mysql_required => false))

  remote_backup = find_last_backup(config.backup_prefix, backup_suffix, config.backup_dir)

  abort no_backups_message unless remote_backup

  FileUtils.mkdir_p(config.download_dir)
  FileUtils.mkdir_p(File.dirname(config.unpack_dir))

  begin
    local_encrypted_archive = download(remote_backup, config.download_dir)
    log "expanding #{local_encrypted_archive}"
    unpack(local_encrypted_archive, config.unpack_dir)
  ensure
    unless options[:preserve]
      log "removing #{local_encrypted_archive}"
      FileUtils.rm(local_encrypted_archive)
    end
  end
end