github.com/greenplum-db/gpbackup@v0.0.0-20240517212602-89daab1885b3/ci/scripts/icw-migr-restore.bash (about)

     1  #!/bin/bash
     2  
     3  set -ex
     4  
     5  mkdir /tmp/untarred
     6  tar -xzf gppkgs/gpbackup-gppkgs.tar.gz -C /tmp/untarred
     7  if [[ -d gp-pkg ]] ; then
     8      mkdir /tmp/gppkgv2
     9      tar -xzf gp-pkg/gppkg* -C /tmp/gppkgv2
    10  fi
    11  
    12  # this will dump a folder /tmp/icw-migr-backup with our saved gpbackup results
    13  tar -xzf migration-backup/migration-backup.tar.gz -C /tmp
    14  
    15  if [[ ! -f bin_gpdb/bin_gpdb.tar.gz ]] ; then
    16    mv bin_gpdb/*.tar.gz bin_gpdb/bin_gpdb.tar.gz
    17  fi
    18  source gpdb_src/concourse/scripts/common.bash
    19  time install_gpdb
    20  time ./gpdb_src/concourse/scripts/setup_gpadmin_user.bash
    21  time make_cluster
    22  
    23  cat <<SCRIPT > /tmp/icw_restore.bash
    24  #!/bin/bash
    25  
    26  set -ex
    27  
    28  # use "temp build dir" of parent shell
    29  export GOPATH=\${HOME}/go
    30  export PATH=/usr/local/go/bin:\$PATH:\${GOPATH}/bin:/opt/rh/devtoolset-7/root/usr/bin/
    31  mkdir -p \${GOPATH}/bin \${GOPATH}/src/github.com/greenplum-db
    32  cp -R $(pwd)/gpbackup \${GOPATH}/src/github.com/greenplum-db/
    33  
    34  # Install dependencies before sourcing greenplum path. Using the GPDB curl is causing issues.
    35  pushd \${GOPATH}/src/github.com/greenplum-db/gpbackup
    36    make depend
    37  popd
    38  
    39  source /usr/local/greenplum-db-devel/greenplum_path.sh
    40  source $(pwd)/gpdb_src/gpAux/gpdemo/gpdemo-env.sh
    41  
    42  mkdir -p "\${GPHOME}/postgresql"
    43  
    44  # Install gpbackup gppkg
    45  out=\$(psql postgres -c "select version();")
    46  GPDB_VERSION=\$(echo \$out | sed -n 's/.*Greenplum Database \([0-9]\).*/\1/p')
    47  
    48  if [[ -f /tmp/gppkgv2/gppkg ]] ; then
    49      /tmp/gppkgv2/gppkg install -a /tmp/untarred/gpbackup*gp\${GPDB_VERSION}*${OS}*.gppkg
    50  else
    51      gppkg -i /tmp/untarred/gpbackup*gp\${GPDB_VERSION}*${OS}*.gppkg
    52  fi
    53  
    54  # extract timestamp from saved folder, use it to run a restore
    55  TS=\$(ls /tmp/icw-migr-backup/backups/*)
    56  gprestore --timestamp=\$TS --backup-dir=/tmp/icw-migr-backup --create-db --with-globals --on-error-continue | tee /tmp/gpbackup_test.log
    57  
    58  # We expect some errors, so we have to use on-error-continue, but we want to parse for unexpected
    59  # errors so that we will still fail this test when appropriate.  We chain greps here to allow us to
    60  # easily add or remove expected errors in the future.
    61  
    62  # TODO: see if we can extract this to a standalone script, so this can be kept general for migration testing
    63  # Expected Errors:
    64  ##  Resource group option names were changed in GPDB7.  We expect this to throw an error.
    65  
    66  cat /home/gpadmin/gpAdminLogs/gprestore_* | grep -E "ERROR" | grep -Ev "Encountered [0-9]" \
    67      | grep -Ev "ALTER RESOURCE GROUP" \
    68      | grep -Ev "LOG ERRORS" \
    69      | grep -Ev "RAISE EXCEPTION" \
    70      | tee /tmp/error_list.log
    71  
    72  if [[ -s /tmp/error_list.log ]] ; then
    73      echo "Unexpected errors found in gprestore output"
    74      exit 1
    75  fi
    76  
    77  SCRIPT
    78  
    79  chmod +x /tmp/icw_restore.bash
    80  su - gpadmin "/tmp/icw_restore.bash"
    81