Class: Container::Backup::Volumes

Inherits:
Directories show all
Defined in:
lib/container/steps/volumes.rb

Instance Method Summary collapse

Methods inherited from Directories

#backup, #backup_volume, #recover_volume, #start, #stop

Methods inherited from Step

#backup, #backup_path, #container, #image, #initialize, #params, #perform

Constructor Details

This class inherits a constructor from Container::Backup::Step

Instance Method Details

#create_volumeObject



27
28
29
# File 'lib/container/steps/volumes.rb', line 27

def create_volume
  sh "docker volume create #{volume}"
end

#remove_containerObject

  • “backup=[influxdb_data],databases: [influxdb: {user: ${INFLUXDB_ADMIN_USER,password: $INFLUXDB_ADMIN_PASSWORD}]}”



5
6
7
8
9
10
11
12
# File 'lib/container/steps/volumes.rb', line 5

def remove_container
  puts "Remove container #{container} (y/n)?"
  if gets.chomp == 'y'
    sh "docker rm -f #{container}"
  else
    exit
  end
end

#remove_volumeObject



18
19
20
21
22
23
24
25
# File 'lib/container/steps/volumes.rb', line 18

def remove_volume
  puts "Remove volume #{volume} (y/n)?"
  if gets.chomp == 'y'
    sh "docker volume rm #{volume}"
  else
    exit
  end
end

#restoreObject



38
39
40
41
42
43
44
# File 'lib/container/steps/volumes.rb', line 38

def restore
  stop
  remove_container
  remove_volume
  recover_volume
  start
end

#tar_volume(option) ⇒ Object



33
34
35
36
# File 'lib/container/steps/volumes.rb', line 33

def tar_volume(option)
  raise "Invalid tar option #{option}" unless option =~ /\A[cx]\z/
  sh "docker run --rm -v #{volume}:/temp -v #{backup_path}:/backup ubuntu bash -c \"cd /temp && tar #{option}vf /backup/#{volume}.tar #{option == 'c' ? ' .' : ''}\""
end

#volumeObject



14
15
16
# File 'lib/container/steps/volumes.rb', line 14

def volume
  @params
end