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/f3bcdc0e219610b11999f0fbbb6a195f04a46d97 below:

Add an option to configure permission on dump (#138) · orgrim/pg_back@f3bcdc0 · GitHub

@@ -50,6 +50,7 @@ type options struct {

50 50

NoConfigFile bool

51 51

BinDirectory string

52 52

Directory string

53 +

Mode int

53 54

Host string

54 55

Port int

55 56

Username string

@@ -130,6 +131,7 @@ func defaultOptions() options {

130 131

return options{

131 132

NoConfigFile: false,

132 133

Directory: "/var/backups/postgresql",

134 +

Mode: 0o600,

133 135

Format: 'c',

134 136

DirJobs: 1,

135 137

CompressLevel: -1,

@@ -162,6 +164,17 @@ func (*parseCliResult) Error() string {

162 164

return "please exit now"

163 165

}

164 166 167 +

func validateMode(s string) (int, error) {

168 +

if (strings.HasPrefix(s, "0") && len(s) <= 5) || (strings.HasPrefix(s, "-")) {

169 +

mode, err := strconv.ParseInt(s, 0, 32)

170 +

if err != nil {

171 +

return 0, fmt.Errorf("Invalid permission %q", s)

172 +

}

173 +

return int(mode), nil

174 +

}

175 +

return 0, fmt.Errorf("Invalid permission %q, must be octal (start by 0 and max 5 digits) number or negative", s)

176 +

}

177 + 165 178

func validateDumpFormat(s string) error {

166 179

for _, format := range []string{"plain", "custom", "tar", "directory"} {

167 180

// PostgreSQL tools allow the full name of the format and the

@@ -252,7 +265,7 @@ func validateDirectory(s string) error {

252 265

}

253 266 254 267

func parseCli(args []string) (options, []string, error) {

255 -

var format, purgeKeep, purgeInterval string

268 +

var format, mode, purgeKeep, purgeInterval string

256 269 257 270

opts := defaultOptions()

258 271

pce := &parseCliResult{}

@@ -269,6 +282,7 @@ func parseCli(args []string) (options, []string, error) {

269 282

pflag.BoolVar(&opts.NoConfigFile, "no-config-file", false, "skip reading config file\n")

270 283

pflag.StringVarP(&opts.BinDirectory, "bin-directory", "B", "", "PostgreSQL binaries directory. Empty to search $PATH")

271 284

pflag.StringVarP(&opts.Directory, "backup-directory", "b", "/var/backups/postgresql", "store dump files there")

285 +

pflag.StringVarP(&mode, "backup-file-mode", "m", "0600", "mode to apply to dump files")

272 286

pflag.StringVarP(&opts.CfgFile, "config", "c", defaultCfgFile, "alternate config file")

273 287

pflag.StringSliceVarP(&opts.ExcludeDbs, "exclude-dbs", "D", []string{}, "list of databases to exclude")

274 288

pflag.BoolVarP(&opts.WithTemplates, "with-templates", "t", false, "include templates")

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

416 430

changed = append(changed, "include-dbs")

417 431

}

418 432 433 +

parsed_mode, err := validateMode(mode)

434 +

if err != nil {

435 +

return opts, changed, fmt.Errorf("invalid value for --backup-file-mode: %s", err)

436 +

}

437 +

opts.Mode = parsed_mode

438 + 419 439

// Validate purge keep and time limit

420 440

keep, err := validatePurgeKeepValue(purgeKeep)

421 441

if err != nil {

@@ -527,7 +547,7 @@ func validateConfigurationFile(cfg *ini.File) error {

527 547

s, _ := cfg.GetSection(ini.DefaultSection)

528 548 529 549

known_globals := []string{

530 -

"bin_directory", "backup_directory", "timestamp_format", "host", "port", "user",

550 +

"bin_directory", "backup_directory", "backup_file_mode", "timestamp_format", "host", "port", "user",

531 551

"dbname", "exclude_dbs", "include_dbs", "with_templates", "format",

532 552

"parallel_backup_jobs", "compress_level", "jobs", "pause_timeout",

533 553

"purge_older_than", "purge_min_keep", "checksum_algorithm", "pre_backup_hook",

@@ -581,7 +601,7 @@ gkLoop:

581 601

}

582 602 583 603

func loadConfigurationFile(path string) (options, error) {

584 -

var format, purgeKeep, purgeInterval string

604 +

var format, mode, purgeKeep, purgeInterval string

585 605 586 606

opts := defaultOptions()

587 607

@@ -607,6 +627,7 @@ func loadConfigurationFile(path string) (options, error) {

607 627

// flags

608 628

opts.BinDirectory = s.Key("bin_directory").MustString("")

609 629

opts.Directory = s.Key("backup_directory").MustString("/var/backups/postgresql")

630 +

mode = s.Key("backup_file_mode").MustString("0600")

610 631

timeFormat := s.Key("timestamp_format").MustString("rfc3339")

611 632

opts.Host = s.Key("host").MustString("")

612 633

opts.Port = s.Key("port").MustInt(0)

@@ -670,6 +691,13 @@ func loadConfigurationFile(path string) (options, error) {

670 691

opts.AzureKey = s.Key("azure_key").MustString("")

671 692

opts.AzureEndpoint = s.Key("azure_endpoint").MustString("blob.core.windows.net")

672 693 694 +

// Validate mode and convert to int

695 +

m, err := validateMode(mode)

696 +

if err != nil {

697 +

return opts, err

698 +

}

699 +

opts.Mode = m

700 + 673 701

// Validate purge keep and time limit

674 702

keep, err := validatePurgeKeepValue(purgeKeep)

675 703

if err != nil {

@@ -819,6 +847,8 @@ func mergeCliAndConfigOptions(cliOpts options, configOpts options, onCli []strin

819 847

opts.BinDirectory = cliOpts.BinDirectory

820 848

case "backup-directory":

821 849

opts.Directory = cliOpts.Directory

850 +

case "backup-file-mode":

851 +

opts.Mode = cliOpts.Mode

822 852

case "exclude-dbs":

823 853

opts.ExcludeDbs = cliOpts.ExcludeDbs

824 854

case "include-dbs":


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