Skip to content

Commit 1ca84d4

Browse files
committed
Use temporary file for output
1 parent 47694fb commit 1ca84d4

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

backup.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,9 @@ func (b *PostgresBackup) doPostgresBackup() (string, error) {
163163
args = append(args, b.cfg.PostgresDatabase)
164164
}
165165

166-
// Prepare command
167-
cmd := exec.Command("pg_dump", args...)
168-
// Pass password via environment variable
169-
cmd.Env = append(os.Environ(), fmt.Sprintf("PGPASSWORD=%s", b.cfg.PostgresPassword))
170-
171166
// Dump to a timestamped file in the temp directory
172167
ts := time.Now().Format("20060102-150405")
173-
outfile := fmt.Sprintf("%s/%s-backup-%s.sql.gz", b.tempDir, b.cfg.PostgresDatabase, ts)
168+
outfile := fmt.Sprintf("%s/%s-backup-%s.sql", b.tempDir, b.cfg.PostgresDatabase, ts)
174169
f, err := os.Create(outfile)
175170
if err != nil {
176171
slog.Error("Failed to create dump file", "file", outfile, "error", err)
@@ -182,6 +177,12 @@ func (b *PostgresBackup) doPostgresBackup() (string, error) {
182177
slog.Error("Failed to close dump file", "file", outfile, "error", err)
183178
}
184179
}(f)
180+
args = append(args, "-f", outfile)
181+
182+
// Prepare command
183+
cmd := exec.Command("pg_dump", args...)
184+
// Pass password via environment variable
185+
cmd.Env = append(os.Environ(), fmt.Sprintf("PGPASSWORD=%s", b.cfg.PostgresPassword))
185186

186187
// Create gzip writer for compression
187188
gzipWriter := gzip.NewWriter(f)

config.yaml.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ postgres_password: password
3030
# --schema=public --blobs - Backup only the public schema with binary data
3131
# --clean --if-exists - Add DROP commands before CREATE
3232
# --no-owner --no-acl - Exclude owner and ACL information
33-
postgres_extra_opts: '--schema=public --blobs'
33+
postgres_extra_opts: '--schema=public -b'
3434

3535
# S3 Storage Configuration
3636
# Supports AWS S3 and S3-compatible services (MinIO, DigitalOcean Spaces, Cloudflare R2, etc.)

0 commit comments

Comments
 (0)