MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / backupCurrentConfigFile

Function backupCurrentConfigFile

rest/main.go:345–379  ·  view source on GitHub ↗

backupCurrentConfigFile takes the original config path and copies this to a file with -bk appended with a timestamp

(sourcePath string)

Source from the content-addressed store, hash-verified

343
344// backupCurrentConfigFile takes the original config path and copies this to a file with -bk appended with a timestamp
345func backupCurrentConfigFile(sourcePath string) (string, error) {
346 source, err := os.Open(sourcePath)
347 if err != nil {
348 return "", err
349 }
350 defer func() {
351 _ = source.Close()
352 }()
353
354 // Grab file extension
355 fileExtension := filepath.Ext(sourcePath)
356
357 // Remove file extension so we can easily modify filename
358 fileNameWithoutExtension := strings.TrimSuffix(filepath.Base(sourcePath), fileExtension)
359
360 // Modify file name and append file extension back onto it
361 fileName := fmt.Sprintf("%s-backup-%d%s", fileNameWithoutExtension, time.Now().Unix(), fileExtension)
362
363 backupPath := filepath.Join(filepath.Dir(sourcePath), fileName)
364
365 backup, err := os.Create(backupPath)
366 if err != nil {
367 return "", err
368 }
369 defer func() {
370 _ = backup.Close()
371 }()
372
373 _, err = io.Copy(backup, source)
374 if err != nil {
375 return "", err
376 }
377
378 return backupPath, nil
379}
380
381func CreateBootstrapConnectionFromStartupConfig(ctx context.Context, config *StartupConfig, bucketConnectionMode base.BucketConnectionMode) (base.BootstrapConnection, error) {
382 opts := bootstrapConnectionOpts{

Callers 1

automaticConfigUpgradeFunction · 0.85

Calls 2

CloseMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected