+28
-3
lines changedFilter options
+28
-3
lines changed Original file line number Diff line number Diff line change
@@ -131,7 +131,11 @@ encryption of files). To keep things simple, encryption is done using a
131
131
passphrase. To encrypt files, use the `--encrypt` option along with the
132
132
`--cipher-pass` option or `PGBK_PASSPHRASE` environment variable to specify the
133
133
passphrase. When `encrypt` is set to true in the configuration file, the
134
-
`--no-encrypt` option allows to disable encryption on the command line.
134
+
`--no-encrypt` option allows to disable encryption on the command line. By
135
+
default, unencrypted source files are removed when they are successfully
136
+
encrypted. Use the `--encrypt-keep-src` option to keep them or
137
+
`--no-encrypt-keep-src` to force remove them and override the configuration
138
+
file.
135
139
136
140
Encrypted files can be decrypted with the correct passphrase and the
137
141
`--decrypt` option. When `--decrypt` is present on the command line, dumps are
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@ type options struct {
72
72
Verbose bool
73
73
Quiet bool
74
74
Encrypt bool
75
+
EncryptKeepSrc bool
75
76
CipherPassphrase string
76
77
Decrypt bool
77
78
}
@@ -191,6 +192,8 @@ func parseCli(args []string) (options, []string, error) {
191
192
192
193
pflag.BoolVar(&opts.Encrypt, "encrypt", false, "encrypt the dumps")
193
194
NoEncrypt := pflag.Bool("no-encrypt", false, "do not encrypt the dumps")
195
+
pflag.BoolVar(&opts.EncryptKeepSrc, "encrypt-keep-src", false, "keep original files when encrypting")
196
+
NoEncryptKeepSrc := pflag.Bool("no-encrypt-keep-src", false, "do not keep original files when encrypting")
194
197
pflag.BoolVar(&opts.Decrypt, "decrypt", false, "decrypt files in the backup directory")
195
198
pflag.StringVar(&opts.CipherPassphrase, "cipher-pass", "", "cipher passphrase for encryption and decryption\n")
196
199
@@ -233,6 +236,12 @@ func parseCli(args []string) (options, []string, error) {
233
236
changed = append(changed, "encrypt")
234
237
}
235
238
239
+
// Same for encrypt_keep_source = true in the config file
240
+
if *NoEncryptKeepSrc {
241
+
opts.EncryptKeepSrc = false
242
+
changed = append(changed, "encrypt-keep-src")
243
+
}
244
+
236
245
// When --help or --version is given print and tell the caller
237
246
// through the error to exit
238
247
if pce.ShowHelp {
@@ -350,6 +359,7 @@ func loadConfigurationFile(path string) (options, error) {
350
359
opts.PostHook = s.Key("post_backup_hook").MustString("")
351
360
opts.Encrypt = s.Key("encrypt").MustBool(false)
352
361
opts.CipherPassphrase = s.Key("cipher_passphrase").MustString("")
362
+
opts.EncryptKeepSrc = s.Key("encrypt_keep_source").MustBool(false)
353
363
354
364
// Validate purge keep and time limit
355
365
keep, err := validatePurgeKeepValue(purgeKeep)
@@ -539,6 +549,8 @@ func mergeCliAndConfigOptions(cliOpts options, configOpts options, onCli []strin
539
549
opts.PostHook = cliOpts.PostHook
540
550
case "encrypt":
541
551
opts.Encrypt = cliOpts.Encrypt
552
+
case "encrypt-keep-src":
553
+
opts.EncryptKeepSrc = cliOpts.EncryptKeepSrc
542
554
case "cipher-pass":
543
555
opts.CipherPassphrase = cliOpts.CipherPassphrase
544
556
case "decrypt":
Original file line number Diff line number Diff line change
@@ -117,6 +117,7 @@ func encryptFile(path string, password string, keep bool) error {
117
117
}
118
118
119
119
if !keep {
120
+
l.Verboseln("removeing source file:", path)
120
121
src.Close()
121
122
if err := os.Remove(path); err != nil {
122
123
return fmt.Errorf("could not remove %s: %w", path, err)
@@ -155,6 +156,7 @@ func encryptFile(path string, password string, keep bool) error {
155
156
}
156
157
157
158
if !keep {
159
+
l.Verboseln("removeing source file:", path)
158
160
src.Close()
159
161
if err := os.Remove(path); err != nil {
160
162
return fmt.Errorf("could not remove %s: %w", path, err)
Original file line number Diff line number Diff line change
@@ -64,6 +64,9 @@ type dump struct {
64
64
// Cipher passphrase, when not empty cipher the file
65
65
CipherPassphrase string
66
66
67
+
// Keep original files after encryption
68
+
EncryptKeepSrc bool
69
+
67
70
// Result
68
71
When time.Time
69
72
ExitCode int
@@ -208,7 +211,7 @@ func main() {
208
211
}
209
212
210
213
if opts.Encrypt {
211
-
if err = encryptFile(file, opts.CipherPassphrase, false); err != nil {
214
+
if err = encryptFile(file, opts.CipherPassphrase, opts.EncryptKeepSrc); err != nil {
212
215
l.Warnln("encryption failed", err)
213
216
}
214
217
}
@@ -310,6 +313,7 @@ func main() {
310
313
TimeFormat: opts.TimeFormat,
311
314
ConnString: conninfo,
312
315
CipherPassphrase: passphrase,
316
+
EncryptKeepSrc: opts.EncryptKeepSrc,
313
317
ExitCode: -1,
314
318
PgDumpVersion: pgDumpVersion,
315
319
}
@@ -597,7 +601,7 @@ func (d *dump) dump() error {
597
601
// Encrypt the file
598
602
if d.CipherPassphrase != "" {
599
603
l.Infoln("encrypting", file)
600
-
if err = encryptFile(file, d.CipherPassphrase, false); err != nil {
604
+
if err = encryptFile(file, d.CipherPassphrase, d.EncryptKeepSrc); err != nil {
601
605
return fmt.Errorf("encrypt failed: %s", err)
602
606
603
607
}
Original file line number Diff line number Diff line change
@@ -61,6 +61,9 @@ encrypt = false
61
61
# environment variable can be used alternatively.
62
62
cipher_passphrase =
63
63
64
+
# Keep orignal files after encrypting them.
65
+
encrypt_keep_source = false
66
+
64
67
# Purge dumps older than this number of days. If the interval has to
65
68
# be shorter than one day, use a duration with units, h for hours, m
66
69
# for minutes, s for seconds, us for microseconds or ns for
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4