class Backup::Syncer::Base

Attributes

excludes[R]
mirror[RW]

Flag for mirroring the files/directories

path[RW]

Path to store the synced files/directories to

syncer_id[R]

Optional user-defined identifier to differentiate multiple syncers defined within a single backup model. Currently this is only used in the log messages.

Public Class Methods

new(syncer_id = nil) click to toggle source
# File lib/backup/syncer/base.rb, line 23
def initialize(syncer_id = nil)
  @syncer_id = syncer_id

  load_defaults!

  @mirror ||= false
  @directories ||= []
  @excludes ||= []
end

Public Instance Methods

add(path) click to toggle source
# File lib/backup/syncer/base.rb, line 40
def add(path)
  directories << path
end
directories(&block) click to toggle source

Syntactical suger for the DSL for adding directories

# File lib/backup/syncer/base.rb, line 35
def directories(&block)
  return @directories unless block_given?
  instance_eval(&block)
end
exclude(pattern) click to toggle source

For Cloud Syncers, pattern can be a string (with shell-style wildcards) or a regex. For RSync, each pattern will be passed to rsync’s –exclude option.

# File lib/backup/syncer/base.rb, line 47
def exclude(pattern)
  excludes << pattern
end

Private Instance Methods

log!(action) click to toggle source
# File lib/backup/syncer/base.rb, line 58
def log!(action)
  msg = case action
        when :started then "Started..."
        when :finished then "Finished!"
        end
  Logger.info "#{syncer_name} #{msg}"
end
syncer_name() click to toggle source
# File lib/backup/syncer/base.rb, line 53
def syncer_name
  @syncer_name ||= self.class.to_s.sub("Backup::", "") +
    (syncer_id ? " (#{syncer_id})" : "")
end