Skip to content

Commit 4097379

Browse files
authored
Merge pull request #1 from Huskydog9988/additional-args
2 parents 00af060 + 2871c29 commit 4097379

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

backup.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,31 +163,46 @@ func (b Backup) backupContainer(ctx context.Context, options *BackupContainerOpt
163163
func getBackupCommand(jobConfig *JobConfig) ([]string, string) {
164164
if jobConfig.Config["dbType"] == "postgres" {
165165

166-
cmd := []string{"pg_dump", "-c", "-w"}
166+
cmd := []string{"pg_dump"}
167167

168168
// default to postgres user
169169
pgUser := "postgres"
170+
171+
// if we have a custom user, use it
170172
if jobConfig.Config["dbUser"] != "" {
171173

172174
log.Debugf("Using custom postgres user: %s", jobConfig.Config["dbUser"])
173175
pgUser = jobConfig.Config["dbUser"]
174176
} else {
175177
log.Debugf("Using default postgres user: %s", jobConfig.Config["dbUser"])
176178
}
179+
// add the user to the command
177180
cmd = append(cmd, "-U", pgUser)
178181

179-
// if we have a password, we need to pass it to the command
182+
// if we have a password, we need add the password flag
180183
if jobConfig.Config["dbPassword"] != "" {
181184
cmd = append(cmd, "--password")
182185
}
183186

187+
// add additional args to the command
188+
if jobConfig.Config["dbAdditionalArgs"] != "" {
189+
cmd = append(cmd, jobConfig.Config["dbAdditionalArgs"])
190+
}
191+
184192
// https://www.postgresql.org/docs/current/app-pg-dumpall.html
185193
return cmd, jobConfig.Config["dbPassword"]
186194
}
187195

196+
// if jobConfig.Config["dbType"] == "mariadb" {
197+
// cmd := []string{"mariadb-dump"}
198+
199+
// return cmd, jobConfig.Config["dbPassword"]
200+
// }
201+
188202
return []string{"echo", "Unknown db type"}, ""
189203
}
190204

205+
// generate the backup file name
191206
func getBackupFileName(jobConfig *JobConfig, containerName string) string {
192207
// currentTime := time.Now()
193208

config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
# optional: allows you to specify a custom db password for cmd to use
2121
# postgres shouldn't need this, but mysql and mariadb will
2222
dbPassword: "postgres"
23+
# optional: allows you to specify additional arguments to pass to the dump cmd
24+
dbAdditionalArgs: "--clean"
2325

2426
# optional: you can specify multiple jobs
2527
textExact:

test/compose.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,3 @@ services:
1919
volumes:
2020
# - ./postgres1:/var/lib/postgresql/data
2121
- ./out/postgres2:/out
22-
23-
adminer:
24-
image: adminer
25-
ports:
26-
- 8080:8080

0 commit comments

Comments
 (0)