Class: BackupRestore::Backuper

Inherits:
Object
  • Object
show all
Defined in:
lib/backup_restore/backuper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id, opts = {}) ⇒ Backuper

Returns a new instance of Backuper.



10
11
12
13
14
15
16
17
18
19
# File 'lib/backup_restore/backuper.rb', line 10

def initialize(user_id, opts = {})
  @user_id = user_id
  @client_id = opts[:client_id]
  @publish_to_message_bus = opts[:publish_to_message_bus] || false
  @with_uploads = opts[:with_uploads] == false ? false : include_uploads?
  @filename_override = opts[:filename]
  @ticket = opts[:ticket]

  initialize_state
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



8
9
10
# File 'lib/backup_restore/backuper.rb', line 8

def store
  @store
end

#successObject (readonly)

Returns the value of attribute success.



8
9
10
# File 'lib/backup_restore/backuper.rb', line 8

def success
  @success
end

Instance Method Details

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/backup_restore/backuper.rb', line 21

def run
  ensure_no_operation_is_running
  ensure_we_have_a_user

  log "[STARTED]"
  log "'#{@user.username}' has started the backup!"

  mark_backup_as_running

  listen_for_shutdown_signal

  ensure_directory_exists(@tmp_directory)
  ensure_directory_exists(@archive_directory)

  
  dump_public_schema

  log "Finalizing backup..."

  @with_uploads ? create_archive : move_dump_backup
  upload_archive

  after_create_hook
rescue SystemExit
  log "Backup process was cancelled!"
rescue Exception => ex
  log "EXCEPTION: " + ex.message
  log ex.backtrace.join("\n")
else
  @success = true
  @backup_filename
ensure
  delete_old
  clean_up
  notify_user
  log "Finished!"
  publish_completion
end