Class: BackupDemon::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/backup_demon/daemon.rb

Instance Method Summary collapse

Constructor Details

#initialize(directories, device_path, mount_point = "/mnt/backuphdd") ⇒ Daemon

Returns a new instance of Daemon.



5
6
7
8
9
# File 'lib/backup_demon/daemon.rb', line 5

def initialize(directories, device_path, mount_point = "/mnt/backuphdd")
  @directories = [directories].flatten
  @drive = Device.new(device_path)
  @mount_point = mount_point
end

Instance Method Details

#pidObject



51
52
53
# File 'lib/backup_demon/daemon.rb', line 51

def pid
  @pid ||= Process.pid
end

#procline(string) ⇒ Object



47
48
49
# File 'lib/backup_demon/daemon.rb', line 47

def procline(string)
  $0 = "backup_demon: #{string}"
end

#run(interval = 5.0) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/backup_demon/daemon.rb', line 11

def run(interval = 5.0)
  interval = Float(interval)

  if @drive.exists? && @drive.different?
    procline 'Found Drive'

    Notifier.alert("Starting Backup") do
      "Starting Backup on #{Date.today}"
    end

    if @drive.mount(@mount_point)
      @directories.each do |source|
        procline "Backing up #{source}"
        Sync.start(source, @drive.mount_point)
      end
      @drive.unmount

      Notifier.alert("Backup Complete") do
        "Backup Complete on #{Date.today}"
      end
    else
      Notifier.alert("Backup Error") do
        "Unable to mount the backup disk."
      end
    end   
  end
  procline 'waiting for drive...'
  Kernel.sleep(interval)
end

#run!(interval = 5.0) ⇒ Object



41
42
43
44
45
# File 'lib/backup_demon/daemon.rb', line 41

def run!(interval = 5.0)
  loop do
    run(interval)
  end
end