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
@@ -94,6 +94,7 @@
|
||||
[ "Last backup", backup ? "#{l(backup.created_at, format: :short)} · #{backup.ok ? number_to_human_size(backup.bytes) : 'FAILED'}" : "not run yet" ],
|
||||
[ "Backup check", backup&.message ],
|
||||
[ "Backups kept", "#{Setting.integer('backups_kept')} (in storage/backups)" ],
|
||||
[ "Off-site backup", OffsiteConnection.connected? ? ((o = OffsiteRun.latest_backup) ? tag.span("#{o.ok ? 'OK' : 'FAILED'} #{o.created_at.to_date}", class: (o.ok && o.recent? ? nil : "badge-orange")) + " · Google Drive (#{OffsiteConnection.current.account_email})" : "Google Drive connected, none yet") : link_to("not set up", admin_offsite_backup_path, class: "badge-orange") ],
|
||||
[ "Procedures", (r = ProceduresRevision.current) ? "Revision #{r.number}, adopted #{r.adopted_at.to_date}" : tag.span("not adopted", class: "badge-orange") ],
|
||||
[ "Last audit", AuditRun.latest ? "#{AuditRun.latest.performed_at.to_date} · #{AuditRun.latest.passed ? 'passed' : 'items not passed'}" : "none yet" ],
|
||||
[ "Next audit due", AuditRun.due_soon? ? tag.span(AuditRun.next_due.to_s, class: "badge-orange") : AuditRun.next_due.to_s ]
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
<% RecordsAudit::MANUAL.each do |key, title| %>
|
||||
<div class="space-y-2 rounded-md p-3 ring-1 ring-slate-200">
|
||||
<label class="flex items-start gap-2 text-sm font-medium"><%= check_box_tag "answers[#{key}][passed]", "1", false, class: "mt-0.5 h-4 w-4 shrink-0 rounded border-slate-300" %><span><%= title %></span></label>
|
||||
<% if key == "restore_test" && OffsiteConnection.connected? %>
|
||||
<p class="ml-6 text-xs text-slate-600">
|
||||
<% if (rt = @audit.restore_test) %>Last automatic restore test (<%= rt.created_at.to_date %>): <span class="<%= rt.ok ? 'badge-green' : 'badge-red' %>"><%= rt.ok ? "OK" : "Failed" %></span> <%= rt.message %><% else %>No automatic restore test yet.<% end %>
|
||||
<%= link_to "Run one", admin_offsite_backup_path, class: "link", target: "_blank" %> (Admin → Off-site Backup → Test restore), then also open a copy downloaded from Google Drive yourself.
|
||||
</p>
|
||||
<% end %>
|
||||
<% if key == "sample" %>
|
||||
<ul class="ml-6 list-disc text-xs text-slate-600">
|
||||
<% sample.each do |e| %><li><%= hidden_field_tag "sample_ids[]", e.id, id: nil %><%= link_to "#{e.aircraft.tail_number} · #{e.date} · #{e.text.truncate(80)}", aircraft_logbook_entry_path(e.aircraft, e), class: "link", target: "_blank" %><%= " (signed)" if e.signature %></li><% end %>
|
||||
|
||||
@@ -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>
|
||||
@@ -34,7 +34,7 @@
|
||||
<li><strong>Software:</strong> Simple Aircraft Manager, version <%= info.revision %> (Ruby <%= RUBY_VERSION %>, Rails <%= Rails.version %>, SQLite <%= SQLite3::SQLITE_VERSION %>).</li>
|
||||
<li><strong>Hosting and network:</strong> <%= policy.hosting_description.presence || "[describe the server, location and network]" %> Access is over HTTPS<%= " with single sign-on (#{Sso.label})" if Sso.enabled? %>.</li>
|
||||
<li><strong>Data:</strong> one SQLite database plus uploaded files (stored once per identical file) on the server's storage volume.</li>
|
||||
<li><strong>Backups:</strong> every night the app makes a verified copy of the database in the storage volume (SQLite integrity check and record counts compared) and keeps the newest <%= Setting.integer("backups_kept") %>. Off-site: <%= policy.offsite_backup_description.presence || "[describe the off-site backup]" %></li>
|
||||
<li><strong>Backups:</strong> every night the app makes a verified copy of the database in the storage volume (SQLite integrity check and record counts compared) and keeps the newest <%= Setting.integer("backups_kept") %>. Off-site: <% if OffsiteConnection.connected? %>after each nightly backup the app copies the verified database snapshot (compressed) to Google Drive (account <%= OffsiteConnection.current.account_email %>, folder “<%= OffsiteConnection::ROOT_FOLDER %>”), keeping the newest <%= Setting.integer("offsite_backups_kept") %>, together with every uploaded file (scans, documents, attachments) not already copied; files are never deleted from the off-site copy. A failed copy is emailed to the administrators. A restore test downloads the newest copy, opens it and checks it, and checks a sample of files against their checksums.<%= " #{policy.offsite_backup_description}" if policy.offsite_backup_description.present? %><% else %><%= policy.offsite_backup_description.presence || "[describe the off-site backup]" %><% end %></li>
|
||||
</ul>
|
||||
|
||||
<h2 class="<%= h2 %>">4. Responsible personnel</h2>
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
</div>
|
||||
<%= f.field :hosting_description, as: :textarea, rows: 2, label: "Hosting and network",
|
||||
placeholder: "Self-hosted on a server at the owner's home, behind a firewall and an authenticating proxy." %>
|
||||
<%= f.field :offsite_backup_description, as: :textarea, rows: 2, label: "Off-site backup",
|
||||
<%= f.field :offsite_backup_description, as: :textarea, rows: 2, label: (OffsiteConnection.connected? ? "Off-site backup (optional: Google Drive is connected)" : "Off-site backup"),
|
||||
hint: (OffsiteConnection.connected? ? "The Google Drive backup is described automatically; add anything else here." : "Or set up the built-in Google Drive backup under Admin → Off-site Backup."),
|
||||
placeholder: "The storage volume is backed up nightly with restic to an encrypted off-site repository; retention 30 days." %>
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
<%= f.field :audit_interval_months, as: :number, min: 1, max: 24, label: "Audit every (months)" %>
|
||||
@@ -36,7 +37,7 @@
|
||||
<%= form_with url: adopt_admin_procedures_path, class: "flex flex-wrap items-end gap-2" do %>
|
||||
<div class="min-w-0 flex-1"><%= label_tag :summary, "What changed", class: "label" %><%= text_field_tag :summary, nil, class: "input", placeholder: current ? "e.g. new mechanic added" : "Initial issue" %></div>
|
||||
<%= submit_tag "Adopt as revision #{(current&.number || 0) + 1}", class: "btn-primary", disabled: !@policy.complete?,
|
||||
title: (@policy.complete? ? nil : "Fill in the operator, responsible person, hosting and off-site backup first") %>
|
||||
title: (@policy.complete? ? nil : "Fill in the operator, responsible person, hosting and off-site backup (or connect Google Drive) first") %>
|
||||
<% end %>
|
||||
</section>
|
||||
<section class="card">
|
||||
|
||||
@@ -28,7 +28,14 @@
|
||||
<%= label_tag "settings[backups_kept]", kept[:label], class: "label" %>
|
||||
<%= number_field_tag "settings[backups_kept]", @values["backups_kept"], id: "settings_backups_kept", min: kept[:in].min, max: kept[:in].max,
|
||||
step: 1, required: true, class: "input w-32" %>
|
||||
<p class="hint">A verified copy of the database is made nightly in storage/backups; this many of the newest are kept. Back up the whole storage volume off the server too.</p>
|
||||
<p class="hint">A verified copy of the database is made nightly in storage/backups; this many of the newest are kept. Back up off the server too: <%= link_to "Off-site Backup", admin_offsite_backup_path, class: "link" %>.</p>
|
||||
</div>
|
||||
<% okept = Setting::INTEGERS["offsite_backups_kept"] %>
|
||||
<div>
|
||||
<%= label_tag "settings[offsite_backups_kept]", okept[:label], class: "label" %>
|
||||
<%= number_field_tag "settings[offsite_backups_kept]", @values["offsite_backups_kept"], id: "settings_offsite_backups_kept", min: okept[:in].min, max: okept[:in].max,
|
||||
step: 1, required: true, class: "input w-32" %>
|
||||
<p class="hint">With off-site backup to Google Drive, this many of the newest nightly database copies are kept there. Uploaded files are copied once and kept.</p>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2"><%= f.submit "Save Settings", class: "btn-primary" %><%= link_to "Cancel", admin_about_path, class: "btn-secondary" %></div>
|
||||
|
||||
Reference in new issue
Block a user