github.com/cloudberrydb/gpbackup@v1.0.3-0.20240118031043-5410fd45eed6/plugins/plugin_test_scale.sh (about)

     1  #!/bin/bash
     2  set -o pipefail
     3  
     4  plugin=$1
     5  plugin_config=$2
     6  MINIMUM_API_VERSION="0.3.0"
     7  
     8  # ----------------------------------------------
     9  # Test suite setup
    10  # This will put small amounts of data in the
    11  # plugin destination location
    12  # ----------------------------------------------
    13  if [ $# -lt 2 ] || [ $# -gt 3 ]
    14    then
    15      echo "Usage: plugin_test_scale.sh [path_to_executable] [plugin_config] [optional_config_for_secondary_destination]"
    16      exit 1
    17  fi
    18  
    19  if [[ "$plugin_config" != /* ]] ; then
    20      echo "Must provide an absolute path to the plugin config"
    21      exit 1
    22  fi
    23  
    24  logdir="/tmp/test_scale_logs"
    25  mkdir -p $logdir
    26  
    27  print_header() {
    28      header="### $1 ###"
    29      len=$(echo $header | awk '{print length}')
    30      printf "%0.s#" $(seq 1 $len) && echo
    31      echo -e "$header"
    32      printf "%0.s#" $(seq 1 $len) && echo
    33  }
    34  
    35  print_time_exec() {
    36    echo $1
    37    time eval $1
    38  }
    39  
    40  test_backup_and_restore_with_plugin() {
    41      config=$1
    42      backup_flags=$2
    43      restore_flags=$3
    44      log_file="$logdir/plugin_test_log_file"
    45      TIMEFORMAT=%R
    46  
    47      if [[ "$plugin" == *gpbackup_ddboost_plugin ]]; then
    48        # save the encrypt key file, if it exists
    49        if [ -f "$COORDINATOR_DATA_DIRECTORY/.encrypt" ] ; then
    50            mv $COORDINATOR_DATA_DIRECTORY/.encrypt /tmp/.encrypt_saved
    51        fi
    52        echo "gpbackup_ddboost_plugin: 66706c6c6e677a6965796f68343365303133336f6c73366b316868326764" > $COORDINATOR_DATA_DIRECTORY/.encrypt
    53      fi
    54  
    55      # Run gpbackup and get return code for error check later
    56      echo
    57      print_header "GPBACKUP $test_db (flags: [${backup_flags}])"
    58      print_time_exec "gpbackup --dbname $test_db --plugin-config $config $backup_flags &> $log_file"
    59      gpbackup_return_code=$?
    60  
    61      # Parse out the backup timestamp for gprestore and plugin delete_backup
    62      timestamp=`head -10 $log_file | grep "Backup Timestamp " | grep -Eo "[[:digit:]]{14}"`
    63      if [ ! $? -eq 0 ]; then
    64          echo "Unable to parse backup timestamp. Check gpbackup log file in ~/gpAdminLogs for details."
    65          echo
    66          cat $log_file
    67          echo
    68          exit 1
    69      fi
    70  
    71      # Check if gpbackup was successful. If not, call plugin
    72      # delete_backup to clean up and then exit with error.
    73      if [ ! $gpbackup_return_code -eq 0 ]; then
    74          echo "gpbackup failed. Check gpbackup log file in ~/gpAdminLogs for details."
    75          $plugin delete_backup $config $timestamp
    76          echo
    77          cat $log_file
    78          echo
    79          exit 1
    80      fi
    81  
    82      # if replication was off during backup, run gpbackup_manager replicate_backup to test replication
    83      if [[ "$plugin" == *gpbackup_ddboost_plugin ]] && [[ "$plugin_config" == *ddboost_config.yaml ]]; then
    84          echo
    85          print_header "GPBACKUP_MANAGER replicate-backup [${timestamp}])"
    86          print_time_exec "gpbackup_manager replicate-backup $timestamp --plugin-config $config &> $log_file"
    87  
    88          if [ ! $? -eq 0 ]; then
    89              echo "gpbackup_manager replicate-backup failed."
    90              echo
    91              cat $log_file
    92              echo
    93              exit 1
    94          fi
    95      fi
    96  
    97      # Run gprestore and check for error. If gprestore failed, call
    98      # plugin delete_backup to clean up and then exit with error.
    99      print_header "GPRESTORE $test_db (flags: [${restore_flags}])"
   100      print_time_exec "gprestore --quiet --timestamp $timestamp --plugin-config $config --create-db --redirect-db restoredb $restore_flags &> $log_file"
   101  
   102      if [ ! $? -eq 0 ]; then
   103          echo "gprestore failed. Check gprestore log file in ~/gpAdminLogs for details."
   104          $plugin delete_backup $config $timestamp
   105          echo
   106          cat $log_file
   107          echo
   108          exit 1
   109      fi
   110  
   111      # drop restoredb to allow next caller to create it
   112      dropdb restoredb
   113  
   114      # replace the encrypt key file to its proper location
   115      if [ -f "/tmp/.encrypt_saved" ] ; then
   116          mv /tmp/.encrypt_saved $COORDINATOR_DATA_DIRECTORY/.encrypt
   117      fi
   118  
   119      # Call plugin delete_backup to clean up. This step is important so
   120      # that the backup location doesn't fill up and run out of disk
   121      # space.
   122      $plugin delete_backup $config $timestamp &> $log_file
   123      if [ ! $? -eq 0 ]; then
   124          echo "Attempt to delete backup $timestamp failed."
   125          echo
   126          cat $log_file
   127          echo
   128          exit 1
   129      fi
   130  }
   131  
   132  # ----------------------------------------------
   133  # Run scale tests for gpbackup and gprestore with plugin with tpchdb
   134  # ----------------------------------------------
   135  test_db=tpchdb
   136  restore_filter="--include-table public.lineitem_100"
   137  #test_backup_and_restore_with_plugin "$plugin_config" "" "--jobs=4"
   138  test_backup_and_restore_with_plugin "$plugin_config" "" "$restore_filter --jobs=4"
   139  
   140  if [[ "$plugin" == *gpbackup_s3_plugin ]]; then
   141    test_backup_and_restore_with_plugin "$plugin_config" "--single-data-file" "$restore_filter"
   142  fi
   143  
   144  test_backup_and_restore_with_plugin "$plugin_config" "--single-data-file --no-compression" "$restore_filter"
   145  test_backup_and_restore_with_plugin "$plugin_config" "--single-data-file --copy-queue-size 4 --no-compression" "--copy-queue-size 4"
   146  if [[ "$plugin" == *gpbackup_ddboost_plugin ]]; then
   147    echo
   148    echo "DISABLED restore_subset"
   149    cp $plugin_config ${plugin_config}_nofilter
   150    echo "  restore_subset: \"off\"" >> ${plugin_config}_nofilter
   151    test_backup_and_restore_with_plugin "${plugin_config}_nofilter" "--single-data-file --no-compression" "$restore_filter"
   152  fi
   153  
   154  
   155  # ----------------------------------------------
   156  # Cleanup test artifacts
   157  # ----------------------------------------------
   158  echo "Cleaning up leftover test artifacts"
   159  rm -r $logdir
   160  
   161  
   162  echo "# ----------------------------------------------"
   163  echo "# Finished gpbackup plugin scale tests"
   164  echo "# ----------------------------------------------"