diff options
author | spag <spag@golwen.net> | 2013-02-06 15:12:26 +0100 |
---|---|---|
committer | spag <spag@golwen.net> | 2013-02-06 15:12:26 +0100 |
commit | e27343e207be877c0977cc1794b754a3bdb9f258 (patch) | |
tree | c5fee76c060f9b7e8a1a82e1b3893a2902f538ef | |
parent | 98b822e2d139ad2c2779ce292f597d25ff6f936c (diff) | |
parent | c26e4b9d27218378f34175ac3410eab5b12a5713 (diff) |
Merge branch 'develop' of github.com:amooma/GS5 into develop
-rw-r--r-- | app/models/backup_job.rb | 23 | ||||
-rw-r--r-- | app/views/backup_jobs/_index_core.html.haml | 26 | ||||
-rw-r--r-- | app/views/backup_jobs/show.html.haml | 2 | ||||
-rw-r--r-- | config/backup.rb | 1 | ||||
-rw-r--r-- | db/migrate/20130205102838_create_backup_jobs.rb | 2 |
5 files changed, 42 insertions, 12 deletions
diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index a90726c..c9bde2b 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -1,26 +1,43 @@ class BackupJob < ActiveRecord::Base attr_accessible :started_at, :finished_at, :state, :directory, :size_of_the_backup + before_create :set_state_to_queued after_create :initiate_backup + after_destroy :delete_the_backup_directory private + def set_state_to_queued + self.state = 'queued' + self.started_at = Time.now + end + def initiate_backup self.delay.make_a_backup end def make_a_backup - if self.finished_at.nil? + if self.finished_at.nil? && self.state == 'queued' + self.state = 'running' + self.save original_directories = Dir.glob('/var/backups/GS5/*') system "backup perform --trigger GS5 --config_file #{Rails.root.join('config','backup.rb')}" self.directory = (Dir.glob('/var/backups/GS5/*') - original_directories).first if self.directory.blank? - self.state = 'unsuccessful' + self.state = 'failed' else - self.size_of_the_backup = (`du -hs #{new_directory}`).split(/\t/).first + file = File::Stat.new(self.directory) + self.size_of_the_backup = file.size self.finished_at = Time.now self.state = 'successful' end self.save end end + + def delete_the_backup_directory + if !self.directory.blank? + require 'fileutils' + FileUtils.rm_rf self.directory + end + end end diff --git a/app/views/backup_jobs/_index_core.html.haml b/app/views/backup_jobs/_index_core.html.haml index 6babf3e..a706424 100644 --- a/app/views/backup_jobs/_index_core.html.haml +++ b/app/views/backup_jobs/_index_core.html.haml @@ -3,15 +3,29 @@ %th= t('backup_jobs.index.started_at') %th= t('backup_jobs.index.finished_at') %th= t('backup_jobs.index.state') - %th= t('backup_jobs.index.directory') %th= t('backup_jobs.index.size_of_the_backup') + %th{:colspan => '2'} - for backup_job in backup_jobs - %tr - %td= backup_job.started_at - %td= backup_job.finished_at + - if backup_job.state == 'queued' + - row_marker = 'warning' + - else + - if backup_job.state == 'failed' + - row_marker = 'error' + - else + - row_marker = '' + %tr{:class => row_marker} + - if backup_job.finished_at.blank? + %td{:colspan => '2'} + = time_ago_in_words(backup_job.started_at) + - else + %td + = l backup_job.started_at, :format => :short + %td + = l backup_job.finished_at, :format => :short %td= backup_job.state - %td= backup_job.directory - %td= backup_job.size_of_the_backup + %td + - if !backup_job.size_of_the_backup.blank? + = number_to_human_size(backup_job.size_of_the_backup, :precision => 2) =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => backup_job}
\ No newline at end of file diff --git a/app/views/backup_jobs/show.html.haml b/app/views/backup_jobs/show.html.haml index 7f021bb..65091b8 100644 --- a/app/views/backup_jobs/show.html.haml +++ b/app/views/backup_jobs/show.html.haml @@ -14,6 +14,6 @@ = @backup_job.directory %p %strong= t('backup_jobs.show.size_of_the_backup') + ":" - = @backup_job.size_of_the_backup + = number_to_human_size(@backup_job.size_of_the_backup, :precision => 2) = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @backup_job }
\ No newline at end of file diff --git a/config/backup.rb b/config/backup.rb index 46ef058..d57a47e 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -46,7 +46,6 @@ Backup::Model.new(:GS5, 'GS5 backup') do # store_with Local do |local| local.path = "/var/backups/" - local.keep = 3 end ## diff --git a/db/migrate/20130205102838_create_backup_jobs.rb b/db/migrate/20130205102838_create_backup_jobs.rb index 0d71421..0994939 100644 --- a/db/migrate/20130205102838_create_backup_jobs.rb +++ b/db/migrate/20130205102838_create_backup_jobs.rb @@ -5,7 +5,7 @@ class CreateBackupJobs < ActiveRecord::Migration t.datetime :finished_at t.string :state t.string :directory - t.string :size_of_the_backup + t.integer :size_of_the_backup t.timestamps end end |