Skip to content

Commit

Permalink
make gooder
Browse files Browse the repository at this point in the history
  • Loading branch information
loftwah committed Sep 1, 2024
1 parent 9596a57 commit 9c51e87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
14 changes: 5 additions & 9 deletions app/jobs/backup_database_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ def perform
# Calculate backup file size before deleting it
backup_size = File.size?(compressed_file)

# Upload to DigitalOcean Spaces and get the signed URL
backup_url = upload_to_spaces(compressed_file)
# Upload to DigitalOcean Spaces (URL not needed anymore)
upload_to_spaces(compressed_file)

# Optionally, delete the local backup files after upload
File.delete(backup_file) if File.exist?(backup_file)
File.delete(compressed_file) if File.exist?(compressed_file)

Rails.logger.info "BackupDatabaseJob: Backup created, compressed, and uploaded successfully: #{compressed_file}"

# Generate a report with the backup size
report = generate_backup_report(environment, compressed_file, "Success", backup_url, nil, backup_size)
# Generate a report without the URL
report = generate_backup_report(environment, compressed_file, "Success", nil, nil, backup_size)

# Send an email with the report
BackupReportMailer.backup_completed(report).deliver_now
Expand Down Expand Up @@ -70,10 +70,6 @@ def upload_to_spaces(file_path)

obj = S3_CLIENT.bucket(bucket_name).object("backups/#{file_name}")
obj.upload_file(file_path)

# Generate a signed URL that expires in 24 hours
signed_url = obj.presigned_url(:get, expires_in: 24 * 60 * 60)

signed_url

end
end
6 changes: 1 addition & 5 deletions app/views/backup_report_mailer/backup_completed.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
<p><strong>Environment:</strong> <%= @report[:environment] %></p>
<p><strong>Timestamp:</strong> <%= @report[:timestamp] %></p>

<% if @report[:backup_url].present? %>
<p><strong>Backup File:</strong> <a href="<%= @report[:backup_url] %>">Download Backup</a></p>
<% else %>
<p><strong>Backup File:</strong> <%= @report[:backup_file] %></p>
<% end %>
<p><strong>Backup File:</strong> The backup is available in your account. Please log in to access and download the backup.</p>

<p><strong>Backup Size:</strong> <%= @report[:backup_size] %> bytes</p>
<p><strong>Status:</strong> <%= @report[:status] %></p>
Expand Down

0 comments on commit 9c51e87

Please sign in to comment.