Skip to content

Commit

Permalink
fixed backup logs tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhbir-singh committed Jul 30, 2018
1 parent 1e6b16d commit 6e3822f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 52 deletions.
12 changes: 4 additions & 8 deletions app/views/rsnapshot_backups/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
br

- alert_type = "alert-danger"
- alert_type = "alert-success" if log[:end_message] == "completed successfully"
- alert_type = "alert-success" unless log[:end_message].index("completed successfully").blank?
- alert_type = "alert-warning" if log[:end_message].blank?

div class="alert #{alert_type} mt-2" role="alert"
Expand All @@ -28,15 +28,11 @@
- else
span = "Finished at: #{log[:end_time]}"

br.d-none
span.d-none = "Location: #{log[:location]}"
br
span = "Location: #{log[:location]}"
br

- @type = "Daily"
- @type = "Weekly" if log[:type] == "gamma"
- @type = "Hourly" if log[:type] == "alpha"

span = "Type: #{@type}"
span.text-capitalize = "Type: #{log[:type]}"
br
- if log[:end_message].blank?
span.text-capitalize = "Status: Incomplete Backup"
Expand Down
71 changes: 27 additions & 44 deletions lib/rsnapshot_backups/rsnapshot_log_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def parse_datetime_string(string)
end

def get_log_file_path
"/var/log/rsnapshot"
"/var/log/rsnapshot.log"
end

def get_sample_log_file_path
Expand All @@ -17,24 +17,38 @@ def get_sample_log_file_path

def parse_log_file
log_enteries = []
File.open(get_sample_log_file_path, "r").each do |line|
if line =~ /\[.*\] \/usr\/bin\/rsnapshot (alpha|beta|gamma): .*/
File.open(get_log_file_path, "r").each do |line|
if line =~ /\[.*\] \/bin\/rsnapshot (daily|weekly|monthly): .*/

unless line.index("started").blank?
type = nil
if line.index("alpha")!=-1
type = "alpha"
elsif line.index("beta")!=-1
type = "beta"
elsif line.index("gamma")!=-1
type = "gamma"
start_message = nil
if !(line.index("daily").nil?)
type = "daily"
start_message = line[44..-1].strip
elsif !(line.index("weekly").nil?)
type = "weekly"
start_message = line[45..-1].strip
elsif !(line.index("monthly").nil?)
type = "monthly"
start_message = line[46..-1].strip
end

log_enteries << {start_time: parse_datetime_string(line[1..19]), type: type, start_message: line[48..-1].strip}
log_enteries << {start_time: parse_datetime_string(line[1..19]), type: type,
start_message: start_message}
else
end_message = nil
if !(line.index("daily").nil?)
end_message = line[44..-1].strip
elsif !(line.index("weekly").nil?)
end_message = line[45..-1].strip
elsif !(line.index("monthly").nil?)
end_message = line[46..-1].strip
end

last_entry = log_enteries.last
last_entry[:end_time]=parse_datetime_string(line[1..19])
last_entry[:end_message]=line[48..-1].strip
last_entry[:end_time] = parse_datetime_string(line[1..19])
last_entry[:end_message] = end_message
log_enteries.pop()
log_enteries << last_entry
end
Expand All @@ -55,38 +69,7 @@ def parse_log_file

def get_log_output
log_enteries = self.parse_log_file
dest_path = RsnapshotHelper.get_fields("snapshot_root")[0][0]

alpha_limit = 6
beta_limit = 7
gamma_limit = 4

alpha_count = beta_count = gamma_count = 0

output = []
log_enteries.reverse.each do |entry|
if entry[:type] == "alpha"
if alpha_count < alpha_limit && entry[:location] == dest_path
alpha_count = alpha_count+1
entry[:location] = entry[:location]+"alpha.#{alpha_count-1}/"
output << entry
end
elsif entry[:type] == "beta"
if beta_count < beta_limit && entry[:location] == dest_path
beta_count = beta_count+1
entry[:location] = entry[:location]+"beta.#{beta_count-1}/"
output << entry
end
elsif entry[:type] == "gamma"
if gamma_count < gamma_limit && entry[:location] == dest_path
gamma_count = gamma_count+1
entry[:location] = entry[:location]+"gamma.#{gamma_count-1}/"
output << entry
end
end
end

output
return log_enteries.reverse
end

end
Expand Down

0 comments on commit 6e3822f

Please sign in to comment.