summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-05 16:21:02 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-05 16:21:02 +0100
commitb1f9f3b2c39d31d0621da36420318406f33a1f92 (patch)
tree6e387c9a04ec3f8efb50fc68d980d25c6be29eda /app
parent3005e0ecb346db7b3d85d610691dea14be21f5f6 (diff)
DelayedJob table upgrade.
Diffstat (limited to 'app')
-rw-r--r--app/models/backup_job.rb21
1 files changed, 16 insertions, 5 deletions
diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb
index b0a588f..a90726c 100644
--- a/app/models/backup_job.rb
+++ b/app/models/backup_job.rb
@@ -1,14 +1,25 @@
class BackupJob < ActiveRecord::Base
attr_accessible :started_at, :finished_at, :state, :directory, :size_of_the_backup
- after_create :start_the_backup
+ after_create :initiate_backup
private
- def start_the_backup
- if self.finished_at.nil?
+ def initiate_backup
+ self.delay.make_a_backup
+ end
+
+ def make_a_backup
+ if self.finished_at.nil?
+ original_directories = Dir.glob('/var/backups/GS5/*')
system "backup perform --trigger GS5 --config_file #{Rails.root.join('config','backup.rb')}"
- self.finished_at = Time.now
- self.status = 'done'
+ self.directory = (Dir.glob('/var/backups/GS5/*') - original_directories).first
+ if self.directory.blank?
+ self.state = 'unsuccessful'
+ else
+ self.size_of_the_backup = (`du -hs #{new_directory}`).split(/\t/).first
+ self.finished_at = Time.now
+ self.state = 'successful'
+ end
self.save
end
end