Files
simple-aircraft-manager-rails/db/migrate/20261108040000_create_offsite_backups.rb
rickyandClaude Opus 5.5 7694719582 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>
2026-11-07 13:51:45 -05:00

38 lines
1.2 KiB
Ruby

class CreateOffsiteBackups < ActiveRecord::Migration[8.1]
def change
# One row: the Google Drive account the off-site copies go to.
create_table :offsite_connections do |t|
t.string :provider, null: false, default: "google_drive"
t.string :client_id
t.text :client_secret
t.text :refresh_token
t.string :account_email
t.string :folder_id
t.string :database_folder_id
t.string :files_folder_id
t.references :connected_by, foreign_key: { to_table: :users }
t.datetime :connected_at
t.timestamps
end
create_table :offsite_runs do |t|
t.string :kind, null: false # backup | restore_test
t.boolean :ok, null: false
t.text :message
t.bigint :bytes
t.integer :files_uploaded, null: false, default: 0
t.json :details
t.timestamps
end
add_index :offsite_runs, [ :kind, :created_at ]
# Uploaded files already copied off-site (by blob), so each goes once.
create_table :offsite_files do |t|
t.references :blob, null: false, index: { unique: true }
t.string :drive_file_id, null: false
t.bigint :bytes
t.timestamps
end
end
end