Class: Container::Backup::Directories

Inherits:
Step
  • Object
show all
Defined in:
lib/container/steps/directories.rb

Direct Known Subclasses

Mysql, Volumes

Instance Method Summary collapse

Methods inherited from Step

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

Constructor Details

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

Instance Method Details

#backupObject



17
18
19
20
21
22
# File 'lib/container/steps/directories.rb', line 17

def backup
  stop
  mkdir_p(backup_path)
  backup_volume
  start
end

#backup_volumeObject



30
31
32
# File 'lib/container/steps/directories.rb', line 30

def backup_volume
  tar_volume('c')
end

#recover_volumeObject



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

def recover_volume
  tar_volume('x')
end

#remove_volumeObject



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

def remove_volume
  puts "Remove all files from #{volume} (y/n)?"
  if gets.chomp  == 'y'
    sh "docker run --rm --volumes-from #{container} ubuntu bash -c \"rm -rf #{volume}\""
  else
    exit
  end
end

#restoreObject



24
25
26
27
28
29
# File 'lib/container/steps/directories.rb', line 24

def restore
  stop
  remove_volume
  recover_volume
  start
end

#startObject



9
10
11
# File 'lib/container/steps/directories.rb', line 9

def start
  sh "#{DockerCompose.docker_compose} up -d #{container}"
end

#stopObject

  • “backup=[/var/www/html/libraries, /var/www/html/modules, /var/www/html/profiles, /var/www/html/themes, /var/www/html/sites]”



5
6
7
# File 'lib/container/steps/directories.rb', line 5

def stop
  sh "#{DockerCompose.docker_compose} stop #{container}"
end

#tar_volume(option) ⇒ Object



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

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