mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Off-site backup to Google Drive
- Admin → Off-site Backup: connect a Google account with your own OAuth client (drive.file scope; refresh token and secret encrypted) - Nightly after the verified database backup: upload the gzipped snapshot (newest N kept, Settings) and every uploaded file not yet copied - Restore test downloads the newest copy, opens and checks it, and checks sampled files against their checksums; failures emailed to admins - About, procedures document, policy completeness and audits use it - offsite:restore_files rake task; restore steps in the admin guide Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fe3fba1736
commit
7694719582
31 files changed
+853
-20
No files matched your search
@@ -0,0 +1,59 @@
|
||||
<% content_for :title, "Off-site backup" %>
|
||||
<h1 class="mb-1 text-2xl font-bold">Off-site backup</h1>
|
||||
<p class="mb-5 max-w-3xl text-sm text-slate-600">Every night, after the verified database backup, the app copies it to Google Drive with every uploaded file not already there, so the records survive losing this server (AC 120-78B 3.2.7). The newest <%= Setting.integer("offsite_backups_kept") %> database copies are kept (<%= link_to "Settings", edit_admin_settings_path, class: "link" %>); uploaded files are copied once and never deleted there. The app can only see the files it created in your Drive.</p>
|
||||
|
||||
<div class="grid gap-5 lg:grid-cols-2">
|
||||
<section class="card card-body space-y-3">
|
||||
<h2 class="card-title">Google Drive</h2>
|
||||
<% if @connection.connected? %>
|
||||
<p class="text-sm"><span class="badge-green">Connected</span> <strong><%= @connection.account_email %></strong>, by <%= @connection.connected_by&.display_name %> on <%= @connection.connected_at&.to_date %>.
|
||||
Folder: <em><%= OffsiteConnection::ROOT_FOLDER %></em>.</p>
|
||||
<p class="text-sm">Uploaded files copied: <%= @files_copied %> of <%= @files_total %>.</p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<%= button_to "Back up now", backup_now_admin_offsite_backup_path, class: "btn-primary" %>
|
||||
<%= button_to "Test restore", restore_test_admin_offsite_backup_path, class: "btn-secondary",
|
||||
title: "Download the newest database copy and a few files from Drive and check them" %>
|
||||
<%= button_to "Disconnect", admin_offsite_backup_path, method: :delete, class: "btn-secondary",
|
||||
form: { data: { turbo_confirm: "Stop copying backups to #{@connection.account_email}? The copies already there stay in that Drive." } } %>
|
||||
</div>
|
||||
<% elsif @connection.configured? %>
|
||||
<p class="text-sm">The OAuth client is saved. Connect the Google account whose Drive will hold the backups.</p>
|
||||
<%= link_to "Connect Google Drive", connect_admin_offsite_backup_path, class: "btn-primary self-start", data: { turbo: false } %>
|
||||
<% else %>
|
||||
<p class="text-sm text-amber-800">Not set up. Follow the steps to create a Google OAuth client, then connect.</p>
|
||||
<% end %>
|
||||
|
||||
<%= form_with model: @connection, url: admin_offsite_backup_path, method: :patch, class: "space-y-3 border-t border-slate-100 pt-3" do |f| %>
|
||||
<%= f.field :client_id, label: "OAuth client ID", placeholder: "1234567890-abc.apps.googleusercontent.com" %>
|
||||
<%= f.field :client_secret, as: :password, label: "OAuth client secret", value: nil,
|
||||
placeholder: (@connection.client_secret.present? ? "saved (leave blank to keep)" : nil), autocomplete: "off" %>
|
||||
<%= f.submit "Save client", class: "btn-secondary" %>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<section class="card card-body space-y-2 text-sm">
|
||||
<h2 class="card-title">Setting up Google (once)</h2>
|
||||
<ol class="list-decimal space-y-1.5 pl-5">
|
||||
<li>Open the <a class="link" href="https://console.cloud.google.com/projectcreate" target="_blank" rel="noopener">Google Cloud console</a> signed in as the account that will hold the backups, and create a project (e.g. “Aircraft records backup”).</li>
|
||||
<li><a class="link" href="https://console.cloud.google.com/apis/library/drive.googleapis.com" target="_blank" rel="noopener">Enable the Google Drive API</a> for it.</li>
|
||||
<li>Under <strong>Google Auth Platform → Branding</strong>, give the app a name and your email; under <strong>Audience</strong> choose <strong>External</strong> and then <strong>Publish app</strong> (in “Testing”, Google expires the access after 7 days). Google doesn't need to verify it: the app only asks for access to files it creates.</li>
|
||||
<li>Under <strong>Clients</strong>, create an <strong>OAuth client ID</strong> of type <strong>Web application</strong> with this authorized redirect URI:
|
||||
<code class="mt-1 block break-all rounded bg-slate-100 px-2 py-1"><%= @connection.redirect_uri %></code>
|
||||
(It must be the address you open the app at; set <code>APP_URL</code> if it isn't.)</li>
|
||||
<li>Paste the client ID and secret here, save, and choose <strong>Connect Google Drive</strong>. Google will warn that the app isn't verified: choose <strong>Advanced → Go to …</strong> and allow access.</li>
|
||||
</ol>
|
||||
<p class="text-slate-600">Restoring: see <%= link_to "Help → Administration", help_page_path("administration", anchor: "restoring-from-google-drive"), class: "link" %>.</p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="card mt-5">
|
||||
<div class="card-header"><h2 class="card-title">Recent runs</h2></div>
|
||||
<% if @runs.any? %>
|
||||
<ul class="divide-y divide-slate-100 text-sm">
|
||||
<% @runs.each do |r| %>
|
||||
<li class="flex items-start gap-3 px-4 py-2"><span class="<%= r.ok ? 'badge-green' : 'badge-red' %>"><%= r.ok ? "OK" : "Failed" %></span>
|
||||
<span><span class="font-medium"><%= r.kind == "restore_test" ? "Restore test" : "Backup" %></span> · <%= l(r.created_at.in_time_zone, format: :short) %><span class="block text-xs text-slate-600"><%= r.message %></span></span></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% else %><%= empty_state "None yet." %><% end %>
|
||||
</section>
|
||||
Reference in new issue
Block a user