A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/orgrim/pg_back/commit/f6f95900d25604cf33ebe210d297cddcdbeaf777 below:

encrypt and decrypt files with age · orgrim/pg_back@f6f9590 · GitHub

@@ -46,31 +46,34 @@ var defaultCfg string

46 46 47 47

// options struct holds command line and configuration file options

48 48

type options struct {

49 -

BinDirectory string

50 -

Directory string

51 -

Host string

52 -

Port int

53 -

Username string

54 -

ConnDb string

55 -

ExcludeDbs []string

56 -

Dbnames []string

57 -

WithTemplates bool

58 -

Format rune

59 -

DirJobs int

60 -

CompressLevel int

61 -

Jobs int

62 -

PauseTimeout int

63 -

PurgeInterval time.Duration

64 -

PurgeKeep int

65 -

SumAlgo string

66 -

PreHook string

67 -

PostHook string

68 -

PgDumpOpts []string

69 -

PerDbOpts map[string]*dbOpts

70 -

CfgFile string

71 -

TimeFormat string

72 -

Verbose bool

73 -

Quiet bool

49 +

BinDirectory string

50 +

Directory string

51 +

Host string

52 +

Port int

53 +

Username string

54 +

ConnDb string

55 +

ExcludeDbs []string

56 +

Dbnames []string

57 +

WithTemplates bool

58 +

Format rune

59 +

DirJobs int

60 +

CompressLevel int

61 +

Jobs int

62 +

PauseTimeout int

63 +

PurgeInterval time.Duration

64 +

PurgeKeep int

65 +

SumAlgo string

66 +

PreHook string

67 +

PostHook string

68 +

PgDumpOpts []string

69 +

PerDbOpts map[string]*dbOpts

70 +

CfgFile string

71 +

TimeFormat string

72 +

Verbose bool

73 +

Quiet bool

74 +

Encrypt bool

75 +

CipherPassphrase string

76 +

Decrypt bool

74 77

}

75 78 76 79

func defaultOptions() options {

@@ -185,6 +188,12 @@ func parseCli(args []string) (options, []string, error) {

185 188

pflag.StringVarP(&purgeKeep, "purge-min-keep", "K", "0", "minimum number of dumps to keep when purging or 'all' to keep everything\n")

186 189

pflag.StringVar(&opts.PreHook, "pre-backup-hook", "", "command to run before taking dumps")

187 190

pflag.StringVar(&opts.PostHook, "post-backup-hook", "", "command to run after taking dumps\n")

191 + 192 +

pflag.BoolVar(&opts.Encrypt, "encrypt", false, "encrypt the dumps")

193 +

NoEncrypt := pflag.Bool("no-encrypt", false, "do not encrypt the dumps")

194 +

pflag.BoolVar(&opts.Decrypt, "decrypt", false, "decrypt files in the backup directory")

195 +

pflag.StringVar(&opts.CipherPassphrase, "cipher-pass", "", "cipher passphrase for encryption and decryption\n")

196 + 188 197

pflag.StringVarP(&opts.Host, "host", "h", "", "database server host or socket directory")

189 198

pflag.IntVarP(&opts.Port, "port", "p", 0, "database server port number")

190 199

pflag.StringVarP(&opts.Username, "username", "U", "", "connect as specified database user")

@@ -217,6 +226,13 @@ func parseCli(args []string) (options, []string, error) {

217 226

changed = append(changed, "with-templates")

218 227

}

219 228 229 +

// To override cipher = true from the config file on the command line,

230 +

// have MergeCliAndConfigOptions() use the false value

231 +

if *NoEncrypt {

232 +

opts.Encrypt = false

233 +

changed = append(changed, "encrypt")

234 +

}

235 + 220 236

// When --help or --version is given print and tell the caller

221 237

// through the error to exit

222 238

if pce.ShowHelp {

@@ -270,6 +286,30 @@ func parseCli(args []string) (options, []string, error) {

270 286 271 287

opts.Format = []rune(format)[0]

272 288 289 +

if opts.Encrypt && opts.Decrypt {

290 +

return opts, changed, fmt.Errorf("options --encrypt and --decrypt are mutually exclusive")

291 +

}

292 + 293 +

// Ensure a non-empty passphrase is set when asking for encryption

294 +

if (opts.Encrypt || opts.Decrypt) && len(opts.CipherPassphrase) == 0 {

295 +

oncli := false

296 +

for _, v := range changed {

297 +

if v == "cipher-pass" {

298 +

oncli = true

299 +

break

300 +

}

301 +

}

302 + 303 +

// Fallback on the environment

304 +

if !oncli {

305 +

opts.CipherPassphrase, _ = os.LookupEnv("PGBK_PASSPHRASE")

306 +

}

307 + 308 +

if len(opts.CipherPassphrase) == 0 {

309 +

return opts, changed, fmt.Errorf("cannot use an empty passphrase for encryption")

310 +

}

311 +

}

312 + 273 313

return opts, changed, nil

274 314

}

275 315

@@ -308,6 +348,8 @@ func loadConfigurationFile(path string) (options, error) {

308 348

opts.SumAlgo = s.Key("checksum_algorithm").MustString("none")

309 349

opts.PreHook = s.Key("pre_backup_hook").MustString("")

310 350

opts.PostHook = s.Key("post_backup_hook").MustString("")

351 +

opts.Encrypt = s.Key("encrypt").MustBool(false)

352 +

opts.CipherPassphrase = s.Key("cipher_passphrase").MustString("")

311 353 312 354

// Validate purge keep and time limit

313 355

keep, err := validatePurgeKeepValue(purgeKeep)

@@ -331,6 +373,10 @@ func loadConfigurationFile(path string) (options, error) {

331 373

}

332 374

opts.Format = []rune(format)[0]

333 375 376 +

if opts.Encrypt && len(opts.CipherPassphrase) == 0 {

377 +

return opts, fmt.Errorf("cannot use an empty passphrase for encryption")

378 +

}

379 + 334 380

// Validate the value of the timestamp format. Force the use of legacy

335 381

// on windows to avoid failure when creating filenames with the

336 382

// timestamp

@@ -491,6 +537,12 @@ func mergeCliAndConfigOptions(cliOpts options, configOpts options, onCli []strin

491 537

opts.PreHook = cliOpts.PreHook

492 538

case "post-backup-hook":

493 539

opts.PostHook = cliOpts.PostHook

540 +

case "encrypt":

541 +

opts.Encrypt = cliOpts.Encrypt

542 +

case "cipher-pass":

543 +

opts.CipherPassphrase = cliOpts.CipherPassphrase

544 +

case "decrypt":

545 +

opts.Decrypt = cliOpts.Decrypt

494 546

case "host":

495 547

opts.Host = cliOpts.Host

496 548

case "port":


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