Class: Backup::Archive

Inherits:
Object
  • Object
show all
Includes:
CLI
Defined in:
lib/backup/archive.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CLI

#mkdir, #rm, #run, #utility

Constructor Details

#initialize(name, &block) ⇒ Archive

Takes the name of the archive and the configuration block



25
26
27
28
29
30
31
32
# File 'lib/backup/archive.rb', line 25

def initialize(name, &block)
  @name         = name.to_sym
  @paths        = Array.new
  @excludes     = Array.new
  @archive_path = File.join(TMP_PATH, TRIGGER, 'archive')

  instance_eval(&block)
end

Instance Attribute Details

#archive_pathObject

Stores the path to the archive directory



21
22
23
# File 'lib/backup/archive.rb', line 21

def archive_path
  @archive_path
end

#excludesObject

Stores an array of different paths/files to exclude



17
18
19
# File 'lib/backup/archive.rb', line 17

def excludes
  @excludes
end

#nameObject

Stores the name of the archive



9
10
11
# File 'lib/backup/archive.rb', line 9

def name
  @name
end

#pathsObject

Stores an array of different paths/files to store



13
14
15
# File 'lib/backup/archive.rb', line 13

def paths
  @paths
end

Instance Method Details

#add(path) ⇒ Object

Adds new paths to the @paths instance variable array



36
37
38
# File 'lib/backup/archive.rb', line 36

def add(path)
  @paths << path
end

#exclude(path) ⇒ Object

Adds new paths to the @excludes instance variable array



42
43
44
# File 'lib/backup/archive.rb', line 42

def exclude(path)
  @excludes << path
end

#perform!Object

Archives all the provided paths in to a single .tar file and places that .tar file in the folder which later will be packaged



49
50
51
52
53
# File 'lib/backup/archive.rb', line 49

def perform!
  mkdir(archive_path)
  Logger.message("#{ self.class } started packaging and archiving #{ paths.map { |path| "\"#{path}\""}.join(", ") }.")
  run("#{ utility(:tar) } -c #{ paths_to_exclude } #{ paths_to_package } 1> '#{ File.join(archive_path, "#{name}.tar") }' 2> /dev/null")
end