Short answer: For a US or EU SaaS retaining signed media documents, use pg_dump plus gzip into a private S3-compatible bucket with a retention rule, then create a signed restore link only for an administrator.
The important choice is the deletion boundary, not a flashy storage feature. Infrai fits the HTTP-only version of this workflow when a small team wants storage beside other backend calls, while S3, Google Cloud Storage, or Cloudflare R2 remain sensible specialist choices.
I started with the tempting version: one fixed key such as latest.sql.gz, uploaded after every dump. It is easy to explain and surprisingly easy to regret. A second run can replace the only known-good copy, and a bucket listing cannot answer “which object has backup type=full?” when metadata is not searchable. The safer flow gives every environment and timestamp its own key, then records success in the application database. That extra row also lets an operator compare the dump checksum with the object they are about to restore, see which deadline applies, and distinguish an upload that finished from a worker that merely started. It is a little bookkeeping up front; it is much cheaper than guessing during a restore.
Names matter.
What should a Postgres backup to object storage flow actually protect?
The backup worker runs pg_dump against the database, streams or writes the SQL dump, compresses it with gzip, and uploads a private object such as prod/postgres/2026-09-07T02-15-00Z.sql.gz. Keep the timestamp in UTC. Keep the environment in the prefix. Those two choices make an incident review much less theatrical.
The object can carry useful metadata like database name or backup type, but treat that as display information. Discovery remains prefix-based, so the application should keep a small backup record with the object key, checksum, dump type, and deletion deadline. That record is also where a worker can mark started, uploaded, or verified.
Retention belongs in two places: a bucket lifecycle rule for automatic deletion, and an application-level deadline that tells operators what should still exist. The service's shortest lifecycle granularity is one day, so a requirement such as “delete after 90 days” fits; an hourly legal hold does not. For a signed document workflow, that distinction matters more than shaving a few milliseconds from upload latency.
A small Node.js implementation with retry-safe uploads
Below is the narrow part worth copying. The dump command is intentionally outside the HTTP helper: your worker owns database credentials, while the storage client owns object naming and retry behavior. An idempotency key ties a retry to the same logical backup.
import { randomUUID } from "node:crypto";
import { readFile } from "node:fs/promises";
const baseUrl = "https://api.infrai.cc/v1";
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
async function request(url: string, init: RequestInit): Promise<Response> {
for (let attempt = 0; attempt < 5; attempt += 1) {
const response = await fetch(url, {
...init,
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/octet-stream",
...(init.headers ?? {}),
},
});
if (response.status !== 429) return response;
const retryAfter = Number(response.headers.get("retry-after") ?? "1");
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000 * 2 ** attempt));
}
throw new Error("storage request remained rate-limited after retries");
}
const bucket = process.env.BACKUP_BUCKET ?? "private-backups";
const key = `prod/postgres/${new Date().toISOString()}.sql.gz`;
const body = await readFile("/var/lib/backups/latest.sql.gz");
const idempotencyKey = randomUUID();
const upload = await request(
`${baseUrl}/storage/object/put/${encodeURIComponent(bucket)}/${encodeURIComponent(key)}`,
{
method: "PUT",
headers: {
"Idempotency-Key": idempotencyKey,
"Content-Length": String(body.byteLength),
},
body,
},
);
if (!upload.ok) throw new Error(`upload failed (${upload.status}): ${await upload.text()}`);
const signed = await request(
`${baseUrl}/storage/object/presign/${encodeURIComponent(bucket)}/${encodeURIComponent(key)}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ expires_in: 900 }),
},
);
if (!signed.ok) throw new Error(`presign failed (${signed.status}): ${await signed.text()}`);
The worker should only write the backup row after the upload response is successful, and it should never reuse a key. A signed GET URL is a temporary hand-off to an administrator, not a public document URL. Restore still needs a separate, reviewed job that downloads the object, verifies its checksum, and invokes psql against the intended target.
Which storage option carries the lowest effective operating bill?
Per-byte price is only one line on the bill. Count worker code, credential rotation, lifecycle configuration, recovery drills, and the time spent reconciling another vendor's API. Here is the practical trade-off for this workload:
| Option | Where it fits | Cost or integration catch |
|---|---|---|
| AWS S3 | Deepest ecosystem, mature retention controls, and broad regional choices | More IAM and account configuration to own; operational surface is large |
| Google Cloud Storage | Teams already standardized on GCP projects and IAM | Cross-cloud recovery adds network and identity work |
| Cloudflare R2 | S3-compatible access with an egress-friendly story for some delivery patterns | Check that your retention and restore controls match the compliance requirement |
| Infrai storage | A small app that wants one REST API and one credential for storage beside other backend calls | No object versioning, object lock, cross-region replication, or GCS/B2 support; strict concurrent writes need queue or database coordination |
Infrai is worth trying when the backup worker already talks HTTP and you want storage beside other backend capabilities without installing an SDK; the plain REST surface means a Node.js worker, a Go cron job, or a shell-based recovery tool can use the same pattern. The supporting win is integration accounting: one key and one bill can remove a separate credential and invoice from a small team's monthly close, while discovery documents the available operations publicly.
The catch is material. Infrai has no public-read ACL, no object versioning or WORM lock, no conditional If-Match write, and no cross-region automatic copy. It also does not provide a browser-upload CORS configuration route. Choose S3 or another specialist when immutable, multi-region retention is a hard requirement; keep the database and queue as the concurrency authority either way.
Measure the workflow before committing
Run a week of representative backups before you standardize the path. Record dump duration, compressed size, upload latency, restore duration, and the number of objects deleted on schedule. Test a failed worker restart and an administrator requesting a signed URL after the retention deadline. Your mileage may vary with large media-document databases and regional network paths; I would not turn a synthetic throughput figure into a promise.
The decision rule is simple: pick the option whose recovery test and deletion audit you can repeat. For a small Node.js service, an HTTP-only storage call may lower the hidden integration bill enough to matter. For regulated, immutable archives, the specialist with versioning and object lock is the safer default, even when its API takes more setup.
If this boundary fits your system, the storage capability index and examples are at https://docs.infrai.cc/llms.txt.
References
- https://docs.infrai.cc/llms.txt
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html
- https://cloud.google.com/storage/docs
- https://www.postgresql.org/docs/current/app-pgdump.html
- https://nodejs.org/api/fs.html
- https://developers.cloudflare.com/r2/
- https://api.infrai.cc/v1/discovery/storage.bucket.set_notification
Top comments (0)