Hengshi Sense 3.0 upgrades the built-in engine from GP5 to GP6 as compared to the 2.x version.
Assuming the desired installation directory is /opt/hengshi
HENGSHI_HOME=/opt/hengshi
du ${HENGSHI_HOME}/engine-cluster -sch
During the migration process, an additional twice the amount of free space of the data size found above is required, with once the space for exporting data and once the space for importing into GP6.
The following operations are performed on the Master machine of GP. During the gpbackup phase, all Segments will parallelly write data into the local directory specified by the backup-dir parameter on their respective machines; likewise, gprestore will also have all Segments locate the backup data files on their own machines for loading.
1 Stop all services and only start the engine
HENGSHI_HOME=/opt/hengshi
${HENGSHI_HOME}/bin/hengshi-sense-bin stop all
${HENGSHI_HOME}/bin/hengshi-sense-bin start engine
2 Prepare the hengshi-sense installation package and unzip to hengshi-[version] directory, directory preparation process
3 Prepare migration tools
cd hengshi-[version]
wget http://download.hengshi.io/3rd/pivotal_greenplum_backup_restore-1.15.0-1.tar.gz
4 Update the configuration about the engine
HENGSHI_HOME=/opt/hengshi
cd ${HENGSHI_HOME}
test -f conf/hengshi-sense-env.sh || cp conf/hengshi-sense-env.sh.sample conf/hengshi-sense-env.sh
set_kv_config() {
local config_file="$1"
local param="$2"
local val="$3"
# edit param=val if exist or insert new param=val
grep -E "^\s*${param}\s*=" "${config_file}" > /dev/null \
|| sed -i "$ a ${param}=${val}" "${config_file}"
}
set_kv_config conf/hengshi-sense-env.sh HS_PG_DB postgres
set_kv_config conf/hengshi-sense-env.sh HS_PG_USR postgres
set_kv_config conf/hengshi-sense-env.sh HS_PG_PWD postgres
set_kv_config conf/hengshi-sense-env.sh HS_ENGINE_DB postgres
set_kv_config conf/hengshi-sense-env.sh HS_ENGINE_USR postgres
set_kv_config conf/hengshi-sense-env.sh HS_ENGINE_PWD postgres
5 Export GP5 data, select the directory for storing exported data, which requires free space that is once the size of the current data. For example: ${HENGSHI_HOME}/gpbackup
export HENGSHI_HOME=/opt/hengshi
cd hengshi-[version]
tar -xf pivotal_greenplum_backup_restore-1.15.0-1.tar.gz -C ${HENGSHI_HOME}/lib/gpdb/gpdb/ #must execute, unzip to the current GP5 symlink directory
bash #launch a new bash
source ${HENGSHI_HOME}/engine-cluster/export-cluster.sh
psql postgres -c "drop function if exists public.safe_to_number(text)"
# backup
gpbackup --dbname postgres --backup-dir ${HENGSHI_HOME}/gpbackup --compression-level 9
exit #exit new bash
Notes:
--backup-dir
.--compression-level
is 1-9, the higher the value, the higher the compression ratio and the longer it takes. Based on self-test results, when the level is 6, it takes about 1 hour for 100G, and the size of the backup is nearly 30G (for reference only).1 Stop GP5 and start GP6
HENGSHI_HOME=/opt/hengshi
cd hengshi-[version]
cp -r lib/gpdb-6* ${HENGSHI_HOME}/lib
cd ${HENGSHI_HOME}
bin/hengshi-sense-bin stop engine
mv engine-cluster engine-cluster.gp5.bak
gpdb_name=$(ls ${HENGSHI_HOME}/lib/gpdb-* -dvr --color=never| head -n 1)
gpdb_name=${gpdb_name##*/}
rm -f ${HENGSHI_HOME}/lib/gpdb
cd ${HENGSHI_HOME}/lib
ln -sf ${gpdb_name} ${HENGSHI_HOME}/lib/gpdb
cd ${HENGSHI_HOME}
bin/hengshi-sense-bin init engine
bin/hengshi-sense-bin start engine
2 Import data
export HENGSHI_HOME=/opt/hengshi
cd hengshi-[version]
tar -xf pivotal_greenplum_backup_restore-1.15.0-1.tar.gz -C ${HENGSHI_HOME}/lib/gpdb/gpdb/ #must execute, unzip to the current GP6 symlink directory
bash #launch a new bash
source ${HENGSHI_HOME}/engine-cluster/export-cluster.sh
# find all timestamp (14chars)
find ${HENGSHI_HOME}/gpbackup/SegDataDir-1/backups/ -maxdepth 2 | sort
# restore with a timestamp
gprestore --backup-dir ${HENGSHI_HOME}/gpbackup --timestamp xxxxxxxxxxxxxx
exit #exit new bash
Notes:
cd ${HENGSHI_HOME}
bin/hengshi-sense-bin stop engine
rm -rf engine-cluster
bin/hengshi-sense-bin init engine
bin/hengshi-sense-bin start engine
--with-globals
option, but you might be prompted that roles or queues, etc., already exist, so you need to check before importing and delete them; or you can ignore by specifying the --on-error-continue
option, but this option will ignore all errors, so use with caution.safe_to_number
does not exist, manually create oneCREATE OR REPLACE FUNCTION SAFE_TO_NUMBER(text)
RETURNS numeric IMMUTABLE STRICT AS
$$
BEGIN
RETURN $1::numeric;
EXCEPTION WHEN OTHERS THEN
RETURN NULL;
END
$$ LANGUAGE plpgsql;
--create-db
option to automatically create the database. If it already exists, do not specify it, or else an error will be thrown.--metadata-only
to only import metadata, including table creation but not data.--data-only
to only import data and not include table creation.1 Stop all services
HENGSHI_HOME=/opt/hengshi
${HENGSHI_HOME}/bin/hengshi-sense-bin stop all
2 Delete the GP6 data directory
HENGSHI_HOME=/opt/hengshi
cd ${HENGSHI_HOME}
test -d engine-cluster.gp5.bak && rm -rf engine-cluster
3 Restore GP5
HENGSHI_HOME=/opt/hengshi
cd ${HENGSHI_HOME}
mv engine-cluster.gp5.bak engine-cluster
gpdb_name=$(ls ${HENGSHI_HOME}/lib/gpdb-5* -dvr --color=never| head -n 1)
gpdb_name=${gpdb_name##*/}
rm -f ${HENGSHI_HOME}/lib/gpdb
cd ${HENGSHI_HOME}/lib
ln -sf ${gpdb_name} ${HENGSHI_HOME}/lib/gpdb
HENGSHI_HOME=/opt/hengshi
cd ${HENGSHI_HOME}
rm -rf engine-cluster.gp5.bak
rm -rf lib/gpdb-5*