backupCurrentConfigFile takes the original config path and copies this to a file with -bk appended with a timestamp
(sourcePath string)
| 343 | |
| 344 | // backupCurrentConfigFile takes the original config path and copies this to a file with -bk appended with a timestamp |
| 345 | func 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 | |
| 381 | func CreateBootstrapConnectionFromStartupConfig(ctx context.Context, config *StartupConfig, bucketConnectionMode base.BucketConnectionMode) (base.BootstrapConnection, error) { |
| 382 | opts := bootstrapConnectionOpts{ |
no test coverage detected