Skip to content

Postgres Economy DB support - #4

Open
lukasbischof wants to merge 6 commits into
mainfrom
feature/economy-db-support
Open

Postgres Economy DB support#4
lukasbischof wants to merge 6 commits into
mainfrom
feature/economy-db-support

Conversation

@lukasbischof

@lukasbischof lukasbischof commented Jul 30, 2026

Copy link
Copy Markdown
Member

As we moved most of our databases to the economy tier, I now miss the pg backups download command. This PR implements it as backups finally got implemented by Nine 🎉 . It works like this:

  1. We find the database you want to download
  2. We find the corresponding bucket by first listing all buckets and then matching the name. Probably is much easier with serviceconnections, but as we don't use them everywhere yet, I prefer to not rely on them
  3. We find the corresponding bucketuser, using the same name as the bucket (the non-admin user)
  4. We download the backup using a separate third-party tool called rclone

Download:

$ ruby -Ilib ./bin/deploio pg backups download renuo-chess-tracker-main --output ~/Downloads/test.sql.zst
> rclone copyto DEPLOIO:postgresdatabase-main-cffe5c3/PostgresDatabase-1c62958_53f1258-2026-07-30-0224.sql.zst /Users/lukas/Downloads/test.sql.zst --progress --stats-one-line --s3-no-check-bucket
21.471 KiB / 21.471 KiB, 100%, 0 B/s, ETA -
✓ Downloaded backup from 2026-07-30 04:24 to /Users/lukas/Downloads/test.sql.zst

List:

$ ruby -Ilib ./bin/deploio pg backups list renuo-chess-tracker-main                                      
┌───────────────────┬───────────┬───────────────────────────────────────────────────────────┐
│ DATE              │ SIZE      │ NAME                                                      │
├───────────────────┼───────────┼───────────────────────────────────────────────────────────┤
│ 2026-07-30 04:24  │ 21.5 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-30-0224.sql.zst  │
│ 2026-07-29 04:24  │ 21.5 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-29-0224.sql.zst  │
│ 2026-07-28 04:27  │ 21.5 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-28-0227.sql.zst  │
│ 2026-07-27 04:27  │ 21.4 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-27-0227.sql.zst  │
│ 2026-07-26 04:25  │ 21.4 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-26-0225.sql.zst  │
│ 2026-07-25 04:25  │ 21.4 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-25-0225.sql.zst  │
│ 2026-07-24 04:23  │ 21.1 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-24-0223.sql.zst  │
│ 2026-07-23 04:27  │ 21.1 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-23-0227.sql.zst  │
│ 2026-07-22 04:24  │ 21.2 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-22-0224.sql.zst  │
│ 2026-07-21 04:26  │ 21.1 KiB  │ PostgresDatabase-1c62958_53f1258-2026-07-21-0226.sql.zst  │
└───────────────────┴───────────┴───────────────────────────────────────────────────────────┘

@lukasbischof lukasbischof self-assigned this Jul 30, 2026
@lukasbischof
lukasbischof force-pushed the feature/economy-db-support branch from fac2e86 to 3087d81 Compare July 30, 2026 09:25
The backup is already compressed, so compressing again makes little
sense
@lukasbischof
lukasbischof force-pushed the feature/economy-db-support branch from 3087d81 to 2ff7519 Compare July 30, 2026 09:29
Comment on lines +68 to +71
when DEDICATED_KIND
PostgresBackupService.new(data: data, name: name, dry_run: @nctl.dry_run)
when ECONOMY_KIND
PostgresDatabaseBackupService.new(db_ref: db_ref, data: data, nctl_client: @nctl, name: name)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted the logic that previously was inlined here into two services, one for managing dedicated dbs and one for the shared dbs

Comment on lines +22 to 36
def list(name)
backups = backup_service_for(name).backups
if backups.empty?
Output.warning("No backups found for '#{name}'")
return
end

fqdn = data.dig("status", "atProvider", "fqdn")
if fqdn.nil? || fqdn.empty?
Output.error("Database FQDN not found; cannot capture backup.")
exit 1
rows = backups.map do |backup|
[format_time(backup["ModTime"]), format_size(backup["Size"]), backup["Name"]]
end

cmd = ["ssh", "dbadmin@#{fqdn}", "sudo nine-postgresql-backup"]
Output.command(cmd.join(" "))
system(*cmd) unless @nctl.dry_run
Output.table(rows, headers: ["DATE", "SIZE", "NAME"])
rescue Deploio::Error => e
Output.error(e.message)
exit 1
end

@lukasbischof lukasbischof Jul 30, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sneaky new feature: Implemented a list command for economy dbs as it's fairly cheap (we have to list the backups anyway).
Implementing the list for dedicated dbs and actually letting the user chose the backup they want to download is up for a new PR.

Comment thread lib/deploio/cli.rb
Comment on lines -103 to -110
def build_option_args
args = []
args << "--dry-run" if options[:dry_run]
args << "--no-color" if options[:no_color]
args << "--app" << options[:app] if options[:app]
args << "--org" << options[:org] if options[:org]
args
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to shared_options

args << "--app" << merged_options[:app] if merged_options[:app]
args << "--org" << merged_options[:org] if merged_options[:org]
args
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So essentially, you can now have --dry-run everywhere

@lukasbischof
lukasbischof marked this pull request as ready for review July 30, 2026 09:44
@lukasbischof
lukasbischof requested a review from coorasse July 30, 2026 09:48

@coorasse coorasse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the implementation but why do we need the "forwarded options"? I think you can access "parent_options" already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants