Skip to content

Commit 0a6689c

Browse files
committed
Add --dir and add .tar.gz to uploaded object
The `--dir` option allows files to be uploaded to a "subdirectory" on S3. While testing it, I noticed that the uploaded files were missing the `.tar.gz` suffix, so fix that, too. Set the release date for v0.1.1.
1 parent 7a4855b commit 0a6689c

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,16 @@ All notable changes to this project will be documented in this file. It uses the
77
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
88
"Semantic Versioning 2.0.0"
99

10-
## [v0.1.1]To Be Released
10+
## [v0.1.1]2025-04-24
1111

1212
### ⚡ Improvements
1313

14-
New features and other improvements.
14+
* Added the `--dir` option to specify the S3 subdirectory in which to upload
15+
backups.
1516

1617
### 🪲 Bug Fixes
1718

18-
Issues addressed.
19-
20-
### 📔 Notes
21-
22-
Security issues fixed, incompatible changes.
23-
24-
### ⬆️ Dependency Updates
25-
26-
Updates to third party dependencies.
27-
28-
### 🏗️ Build Setup
29-
30-
Changes to how Harpo is built and released.
31-
32-
### 📚 Documentation
33-
34-
Documentation improvements.
19+
* Fixed the name of the file uploaded to S3 to end in `.tar.gz`.
3520

3621
[v0.1.1]: https://github.com/tembo-io/temback/compare/v0.1.1...v0.1.1
3722

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Options
6464

6565
* `--name`: The name of the backup; required
6666
* `--bucket`: Upload to the named S3 bucket
67+
* `--dir`: Upload to the named S3 subdirectory
6768
* `--compress`: Compress into a tarball (ignored with `--bucket`)
6869
* `--host`: The Postgres host name; defaults to `PGHOST` if set
6970
* `--user`: The Postgres username; defaults to `PGUSER` if set

main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type backupConfig struct {
5454
user string
5555
pass string
5656
bucket string
57+
dir string
5758
compress bool
5859
plain bool
5960
clean bool
@@ -69,13 +70,21 @@ func (c *backupConfig) Tarball() string {
6970
return c.name + ".tar.gz"
7071
}
7172

73+
func (c *backupConfig) UploadKey() string {
74+
if c.dir == "" {
75+
return c.Tarball()
76+
}
77+
return c.dir + "/" + c.Tarball()
78+
}
79+
7280
func newConfig() *backupConfig {
7381
cfg := &backupConfig{time: time.Now().UTC()}
7482
flag.StringVar(&cfg.name, "name", "", "Backup name")
7583
flag.StringVar(&cfg.host, "host", os.Getenv("PGHOST"), "Database host name")
7684
flag.StringVar(&cfg.user, "user", os.Getenv("PGUSER"), "Database username")
7785
flag.StringVar(&cfg.pass, "pass", os.Getenv("PGPASSWORD"), "Database password")
7886
flag.StringVar(&cfg.bucket, "bucket", "", "S3 bucket name")
87+
flag.StringVar(&cfg.dir, "dir", "", "S3 bucket directory")
7988
flag.BoolVar(&cfg.compress, "compress", false, "Compress the backup (ignored with --bucket)")
8089
flag.BoolVar(&cfg.plain, "text", false, "Plain text format")
8190
flag.BoolVar(&cfg.clean, "clean", false, "Delete files after upload")
@@ -315,7 +324,7 @@ func upload(cfg *backupConfig) error {
315324

316325
if _, err := client.PutObject(context.Background(), &s3.PutObjectInput{
317326
Bucket: aws.String(cfg.bucket),
318-
Key: aws.String(cfg.name),
327+
Key: aws.String(cfg.UploadKey()),
319328
Body: fh,
320329
ChecksumAlgorithm: types.ChecksumAlgorithmSha256,
321330
ContentType: aws.String("application/gzip"),

0 commit comments

Comments
 (0)