<% content_for :title, "Off-site backup" %>

Off-site backup

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.

Google Drive

<% if @connection.connected? %>

Connected <%= @connection.account_email %>, by <%= @connection.connected_by&.display_name %> on <%= fmt_date(@connection.connected_at&.to_date) %>. Folder: <%= OffsiteConnection::ROOT_FOLDER %>.

Uploaded files copied: <%= @files_copied %> of <%= @files_total %>.

<%= 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." } } %>
<% elsif @connection.configured? %>

The OAuth client is saved. Connect the Google account whose Drive will hold the backups.

<%= link_to "Connect Google Drive", connect_admin_offsite_backup_path, class: "btn-primary self-start", data: { turbo: false } %> <% else %>

Not set up. Follow the steps to create a Google OAuth client, then connect.

<% 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 %>

Setting up Google (once)

  1. Open the Google Cloud console signed in as the account that will hold the backups, and create a project (e.g. “Aircraft records backup”).
  2. Enable the Google Drive API for it.
  3. Under Google Auth Platform → Branding, give the app a name and your email; under Audience choose External and then Publish app (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.
  4. Under Clients, create an OAuth client ID of type Web application with this authorized redirect URI: <%= @connection.redirect_uri %> (It must be the address you open the app at; set APP_URL if it isn't.)
  5. Paste the client ID and secret here, save, and choose Connect Google Drive. Google will warn that the app isn't verified: choose Advanced → Go to … and allow access.

Restoring: see <%= link_to "Help → Administration", help_page_path("administration", anchor: "restoring-from-google-drive"), class: "link" %>.

Recent runs

<% if @runs.any? %> <% else %><%= empty_state "None yet." %><% end %>