Class: Bosh::Director::Jobs::Backup

Inherits:
BaseJob show all
Defined in:
lib/bosh/director/jobs/backup.rb

Instance Attribute Summary collapse

Attributes inherited from BaseJob

#task_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseJob

#begin_stage, #event_log, #logger, perform, #result_file, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log

Constructor Details

#initialize(dest, options = {}) ⇒ Backup

Returns a new instance of Backup.



14
15
16
17
18
19
20
21
# File 'lib/bosh/director/jobs/backup.rb', line 14

def initialize(dest, options={})
  @backup_file = dest
  @tar_gzipper = options.fetch(:tar_gzipper) { Core::TarGzipper.new }
  @blobstore_client = options.fetch(:blobstore) { App.instance.blobstores.blobstore }
  @db_adapter = options.fetch(:db_adapter) { Bosh::Director::DbBackup.create(Config.db_config) }
  @base_dir = options.fetch(:base_dir) { Config.base_dir }
  @log_dir = options.fetch(:log_dir) { Config.log_dir }
end

Instance Attribute Details

#backup_fileObject (readonly)

Returns the value of attribute backup_file.



12
13
14
# File 'lib/bosh/director/jobs/backup.rb', line 12

def backup_file
  @backup_file
end

Class Method Details

.job_typeObject



8
9
10
# File 'lib/bosh/director/jobs/backup.rb', line 8

def self.job_type
  :bosh_backup
end

Instance Method Details

#performObject



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
# File 'lib/bosh/director/jobs/backup.rb', line 23

def perform
  Dir.mktmpdir do |tmp_output_dir|
    event_log.begin_stage('Backing up director', 4)

    files = []

    if @log_dir
      backup_logs("#{tmp_output_dir}/logs.tgz")
      files << 'logs.tgz'
    end

    backup_task_logs("#{tmp_output_dir}/task_logs.tgz")
    files << 'task_logs.tgz'

    backup_database("#{tmp_output_dir}/director_db.sql")
    files << 'director_db.sql'

    backup_blobstore("#{tmp_output_dir}/blobs.tgz")
    files << 'blobs.tgz'

    @tar_gzipper.compress(tmp_output_dir, files, @backup_file)

    "Backup created at #{@backup_file}"
  end
end