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

compute a checksum of global ACL files · orgrim/pg_back@b42f06f · GitHub

@@ -163,8 +163,31 @@ func main() {

163 163

os.Exit(1)

164 164

}

165 165 166 +

// Use another goroutine to compute checksum of other files than

167 +

// dumps. We just have to send the paths of files to it.

168 +

producedFiles := make(chan string)

169 + 170 +

// To stop gracefully, we would close the channel and tell the main

171 +

// goroutine it's done

172 +

ppDone := make(chan bool, 1)

173 +

go func() {

174 +

for {

175 +

file, more := <-producedFiles

176 +

if !more {

177 +

break

178 +

}

179 +

if opts.SumAlgo != "none" {

180 +

if err = checksumFile(file, opts.SumAlgo); err != nil {

181 +

l.Warnln("checksum failed", err)

182 +

continue

183 +

}

184 +

}

185 +

}

186 +

ppDone <- true

187 +

}()

188 + 166 189

l.Infoln("dumping globals")

167 -

if err := dumpGlobals(opts.Directory, opts.TimeFormat, conninfo); err != nil {

190 +

if err := dumpGlobals(opts.Directory, opts.TimeFormat, conninfo, producedFiles); err != nil {

168 191

l.Fatalln("pg_dumpall -g failed:", err)

169 192

postBackupHook(opts.PostHook)

170 193

os.Exit(1)

@@ -174,27 +197,33 @@ func main() {

174 197

if err != nil {

175 198

l.Fatalln("connection to PostgreSQL failed:", err)

176 199

postBackupHook(opts.PostHook)

200 +

close(producedFiles)

201 +

<-ppDone

177 202

os.Exit(1)

178 203

}

179 204

defer db.Close()

180 205 181 206

l.Infoln("dumping instance configuration")

182 207

var verr *pgVersionError

183 -

if err := dumpSettings(opts.Directory, opts.TimeFormat, db); err != nil {

208 +

if err := dumpSettings(opts.Directory, opts.TimeFormat, db, producedFiles); err != nil {

184 209

if errors.As(err, &verr) {

185 210

l.Warnln(err)

186 211

} else {

187 212

db.Close()

188 213

l.Fatalln("could not dump configuration parameters:", err)

189 214

postBackupHook(opts.PostHook)

215 +

close(producedFiles)

216 +

<-ppDone

190 217

os.Exit(1)

191 218

}

192 219

}

193 220 194 -

if err := dumpConfigFiles(opts.Directory, opts.TimeFormat, db); err != nil {

221 +

if err := dumpConfigFiles(opts.Directory, opts.TimeFormat, db, producedFiles); err != nil {

195 222

db.Close()

196 223

l.Fatalln("could not dump configuration files:", err)

197 224

postBackupHook(opts.PostHook)

225 +

close(producedFiles)

226 +

<-ppDone

198 227

os.Exit(1)

199 228

}

200 229

@@ -203,6 +232,8 @@ func main() {

203 232

l.Fatalln(err)

204 233

db.Close()

205 234

postBackupHook(opts.PostHook)

235 +

close(producedFiles)

236 +

<-ppDone

206 237

os.Exit(1)

207 238

}

208 239

l.Verboseln("databases to dump:", databases)

@@ -211,6 +242,8 @@ func main() {

211 242

db.Close()

212 243

l.Fatalln(err)

213 244

postBackupHook(opts.PostHook)

245 +

close(producedFiles)

246 +

<-ppDone

214 247

os.Exit(1)

215 248

}

216 249

@@ -316,6 +349,9 @@ func main() {

316 349 317 350

f.Close()

318 351 352 +

// Have its checksum computed

353 +

producedFiles <- aclpath

354 + 319 355

l.Infoln("dump of ACL and configuration of", dbname, "to", aclpath, "done")

320 356

}

321 357

}

@@ -349,6 +385,8 @@ func main() {

349 385

}

350 386 351 387

postBackupHook(opts.PostHook)

388 +

close(producedFiles)

389 +

<-ppDone

352 390

os.Exit(exitCode)

353 391

}

354 392

@@ -551,7 +589,7 @@ func pgDumpVersion() int {

551 589

return (maj*100+min)*100 + rev

552 590

}

553 591 554 -

func dumpGlobals(dir string, timeFormat string, conninfo *ConnInfo) error {

592 +

func dumpGlobals(dir string, timeFormat string, conninfo *ConnInfo, fc chan<- string) error {

555 593

command := filepath.Join(binDir, "pg_dumpall")

556 594

args := []string{"-g", "-w"}

557 595

@@ -588,10 +626,15 @@ func dumpGlobals(dir string, timeFormat string, conninfo *ConnInfo) error {

588 626

}

589 627

}

590 628

}

629 + 630 +

if fc != nil {

631 +

fc <- file

632 +

}

633 + 591 634

return nil

592 635

}

593 636 594 -

func dumpSettings(dir string, timeFormat string, db *pg) error {

637 +

func dumpSettings(dir string, timeFormat string, db *pg, fc chan<- string) error {

595 638 596 639

file := formatDumpPath(dir, timeFormat, "out", "pg_settings", time.Now())

597 640

@@ -610,12 +653,16 @@ func dumpSettings(dir string, timeFormat string, db *pg) error {

610 653

if err := ioutil.WriteFile(file, []byte(s), 0644); err != nil {

611 654

return err

612 655

}

656 + 657 +

if fc != nil {

658 +

fc <- file

659 +

}

613 660

}

614 661 615 662

return nil

616 663

}

617 664 618 -

func dumpConfigFiles(dir string, timeFormat string, db *pg) error {

665 +

func dumpConfigFiles(dir string, timeFormat string, db *pg, fc chan<- string) error {

619 666

for _, param := range []string{"hba_file", "ident_file"} {

620 667

file := formatDumpPath(dir, timeFormat, "out", param, time.Now())

621 668

@@ -634,6 +681,12 @@ func dumpConfigFiles(dir string, timeFormat string, db *pg) error {

634 681

if err := ioutil.WriteFile(file, []byte(s), 0644); err != nil {

635 682

return err

636 683

}

684 + 685 +

// We have produced a file send it to the channel for

686 +

// further processing

687 +

if fc != nil {

688 +

fc <- file

689 +

}

637 690

}

638 691

}

639 692

return nil


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