Class: DatedBackup::Core

Inherits:
Object
  • Object
show all
Includes:
CommandLine, Tasks
Defined in:
lib/dated_backup/core/tasks.rb,
lib/dated_backup/core/backup_set.rb,
lib/dated_backup/core/command_line.rb,
lib/dated_backup/core/dated_backup.rb,
lib/dated_backup/core/backup_remover.rb

Defined Under Namespace

Modules: CommandLine, Tasks Classes: BackupRemover, BackupSet

Constant Summary collapse

BACKUP_REGEXP =
/[12][0-9]{3}\-[01][0-9]\-[0-3][0-9]\-[0-2][0-9]h\-[0-6][0-9]m\-[0-6][0-9]s/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tasks

#backup_directories, #create_backup, #create_main_backup_directory, #find_latest_backup, #has_backup?, #run_tasks

Methods included from CommandLine

#execute

Constructor Details

#initialize(procs = {}, kernel = Kernel) ⇒ Core

Returns a new instance of Core.



14
15
16
17
18
# File 'lib/dated_backup/core/dated_backup.rb', line 14

def initialize(procs={}, kernel=Kernel)
  @kernel = kernel
  @before_run = procs[:before] || Proc.new {}
  @after_run = procs[:after] || Proc.new {}
end

Instance Attribute Details

#after_runObject (readonly)

Returns the value of attribute after_run.



12
13
14
# File 'lib/dated_backup/core/dated_backup.rb', line 12

def after_run
  @after_run
end

#backup_rootObject

Returns the value of attribute backup_root.



10
11
12
# File 'lib/dated_backup/core/dated_backup.rb', line 10

def backup_root
  @backup_root
end

#before_runObject (readonly)

Returns the value of attribute before_run.



12
13
14
# File 'lib/dated_backup/core/dated_backup.rb', line 12

def before_run
  @before_run
end

#destinationObject

Returns the value of attribute destination.



10
11
12
# File 'lib/dated_backup/core/dated_backup.rb', line 10

def destination
  @destination
end

#kernelObject (readonly)

Returns the value of attribute kernel.



11
12
13
# File 'lib/dated_backup/core/dated_backup.rb', line 11

def kernel
  @kernel
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/dated_backup/core/dated_backup.rb', line 10

def options
  @options
end

#pre_run_commandsObject (readonly)

Returns the value of attribute pre_run_commands.



11
12
13
# File 'lib/dated_backup/core/dated_backup.rb', line 11

def pre_run_commands
  @pre_run_commands
end

#sourcesObject

Returns the value of attribute sources.



10
11
12
# File 'lib/dated_backup/core/dated_backup.rb', line 10

def sources
  @sources
end

#user_domainObject

Returns the value of attribute user_domain.



10
11
12
# File 'lib/dated_backup/core/dated_backup.rb', line 10

def user_domain
  @user_domain
end

Instance Method Details

#check_for_directory_errorsObject



28
29
30
31
32
33
34
# File 'lib/dated_backup/core/dated_backup.rb', line 28

def check_for_directory_errors
  if sources.nil? || sources.empty?
    raise DirectoryError, "No source directory given"
  elsif backup_root.nil? || backup_root.empty?
    raise DirectoryError, "No destination directory given"
  end
end

#runObject

create the first backup, if non-existent

otherwise cp -al (or # replace cp -al a b with cd a && find . -print | cpio -dpl ../b ) and then create the backup of the dirs using rsync -a –delete the files, in the end, should be read only and undeletable



40
41
42
43
44
# File 'lib/dated_backup/core/dated_backup.rb', line 40

def run
  DatedBackup::ExecutionContext.new :before, &@before_run
  run_tasks
  DatedBackup::ExecutionContext.new :after, &@after_run
end

#set_attributes(h = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/dated_backup/core/dated_backup.rb', line 20

def set_attributes(h={})
  parse_command_options(h)
  @destination = generate_backup_filename    
  if @user_domain
    @sources.map! { |src| "#{@user_domain}:#{src}" }
  end        
end