cleanup_data_dir

in files/gitlab-ctl-commands/pg-upgrade.rb [563:594]


def cleanup_data_dir
  unless GitlabCtl::Util.progress_message('Move the old data directory out of the way') do
    run_command(
      "mv #{@db_worker.data_dir} #{@db_worker.tmp_data_dir}.#{@db_worker.initial_version.major}"
    )
  end
    die 'Error moving data for older version, '
  end

  if @instance_type == :patroni_replica || @instance_type == :patroni_standby_leader
    unless GitlabCtl::Util.progress_message('Recreating an empty data directory') do
      run_command("mkdir -p #{@db_worker.data_dir}")
    end
      die "Error refreshing #{@db_worker.data_dir}"
    end
  else
    unless GitlabCtl::Util.progress_message('Rename the new data directory') do
      run_command(
        "mv #{@db_worker.tmp_data_dir}.#{@db_worker.target_version.major} #{@db_worker.data_dir}"
      )
    end
      die "Error moving #{@db_worker.tmp_data_dir}.#{@db_worker.target_version.major} to #{@db_worker.data_dir}"
    end
  end

  unless GitlabCtl::Util.progress_message('Saving the old version information') do
    save_revert_version
  end
    die
  end
end