Skip to content

Commit

Permalink
[BACKPORT 2.20.0][PLAT-11173] Replicated migrate failing with custom …
Browse files Browse the repository at this point in the history
…root directory

Summary:
Original commit: bf34e06 / D29832
Original commit: ca7a291 / D29942
Small bugs in yba-installer backups during replicated-migrate. First was with the custom root
directory and the second was with not terminating when the backup failed (leading to corrupt data).

Test Plan: Test pipeline output.

Reviewers: sanketh, dshubin

Reviewed By: dshubin

Subscribers: yugaware

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D29926
  • Loading branch information
mchiddy committed Nov 3, 2023
1 parent d58434f commit 0026607
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions managed/yba-installer/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func CreateReplicatedBackupScript(output, dataDir, pgUser, pgPort string, verbos
}

args := []string{"create", "--output", output, "--data_dir", dataDir, "--exclude_prometheus",
"--exclude_releases", "--db_username", pgUser, "--db_host", "localhost",
"--db_port", pgPort}
"--exclude_releases", "--disable_version_check", "--db_username", pgUser,
"--db_host", "localhost", "--db_port", pgPort}

if verbose {
args = append(args, "--verbose")
Expand All @@ -89,7 +89,7 @@ func CreateReplicatedBackupScript(output, dataDir, pgUser, pgPort string, verbos
log.Info("Creating a backup of your Replicated YBA Installation.")
out := shell.Run(fileName, args...)
if !out.SucceededOrLog() {
log.Warn(out.Error.Error())
log.Fatal(out.Error.Error())
}

}
Expand Down
9 changes: 4 additions & 5 deletions managed/yba-installer/cmd/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,11 @@ func (prom Prometheus) FinishReplicatedMigrate() error {
return nil
}

func (prom Prometheus) RollbackMigration(uid, gid uint32) error {
rootDir := common.GetReplicatedBaseDir()
func (prom Prometheus) RollbackMigration(uid, gid uint32, replBaseDir string) error {
replDirs := []string{
filepath.Join(rootDir, "prometheusv2"),
filepath.Join(rootDir, "/yugaware/swamper_targets"),
filepath.Join(rootDir, "yugaware/swamper_rules"),
filepath.Join(replBaseDir, "prometheusv2"),
filepath.Join(replBaseDir, "/yugaware/swamper_targets"),
filepath.Join(replBaseDir, "yugaware/swamper_rules"),
}
for _, dir := range replDirs {
if err := common.Chown(dir, fmt.Sprintf("%d", uid), fmt.Sprintf("%d", gid), true); err != nil {
Expand Down
7 changes: 5 additions & 2 deletions managed/yba-installer/cmd/replicated_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ var replicatedMigrationStart = &cobra.Command{
}

// Get the uid and gid used by the prometheus container. This is used for rollback.
entry := config.Get("installRoot")
entry := config.Get("storage_path")
var replicatedInstallRoot string
if entry == replicatedctl.NilConfigEntry {
replicatedInstallRoot = "/opt/yugabyte"
} else {
replicatedInstallRoot = entry.Value
}
common.SetReplicatedBaseDir(replicatedInstallRoot)
state.Replicated.StoragePath = replicatedInstallRoot
checkFile := filepath.Join(replicatedInstallRoot, "prometheusv2/queries.active")
info, err := os.Stat(checkFile)
if err != nil {
Expand Down Expand Up @@ -342,7 +344,8 @@ func rollbackMigrations(state *ybactlstate.State) error {
prom := services[PrometheusServiceName].(Prometheus)
err := prom.RollbackMigration(
state.Replicated.PrometheusFileUser,
state.Replicated.PrometheusFileUser)
state.Replicated.PrometheusFileUser,
state.Replicated.StoragePath)
if err != nil {
log.Fatal("Failed to rollback prometheus migration: " + err.Error())
}
Expand Down
4 changes: 4 additions & 0 deletions managed/yba-installer/pkg/common/directory_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,7 @@ func GetSelfSignedCertsDir() string {
func GetReplicatedBaseDir() string {
return dm.ReplicatedBaseDir()
}

func SetReplicatedBaseDir(dir string) {
dm.replicatedBaseDir = dir
}
1 change: 1 addition & 0 deletions managed/yba-installer/pkg/ybactlstate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type PostgresState struct {
type ReplicatedMigrationState struct {
PrometheusFileUser uint32 `json:"prometheus_file_user"`
PrometheusFileGroup uint32 `json:"prometheus_file_group"`
StoragePath string `json:"storage_path"`
}

func New() *State {
Expand Down

0 comments on commit 0026607

Please sign in to comment.