#! /bin/bash

HS_HOME=/opt/hengshi
PG_HOME=$HS_HOME/lib/pgsql
export PATH=$PATH:$PG_HOME/bin

PG_USR=postgres
PG_PWD=postgres
PG_HOST=127.0.0.1
PG_PORT=54320

# ----------- meta ------------

restore_meta() {
    local dbname="$1"
    echo PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT $dbname -c "create database $dbname"
    PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "create database $dbname"
    echo PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT $dbname -f $dbname.backup.sql
    PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -f $dbname.backup.sql
}

modify_connection() {
    PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "update connection set options='{\"host\": \"10.240.1.1\", \"port\": 5432, \"type\": \"postgresql\", \"config\": {}, \"database\": \"postgres\", \"encoding\": \"UTF-8\", \"password\": \"postgres\", \"username\": \"postgres\"}' where id=3"
    PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "update connection set options='{\"host\": \"10.240.1.1\", \"port\": 5432, \"type\": \"postgresql\", \"config\": {}, \"database\": \"postgres\", \"encoding\": \"UTF-8\", \"password\": \"postgres\", \"username\": \"postgres\"}' where id=4"
    PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "update connection set options='{\"host\": \"10.240.1.1\", \"port\": 5432, \"type\": \"postgresql\", \"config\": {}, \"database\": \"adhoc\", \"encoding\": \"UTF-8\", \"password\": \"postgres\", \"username\": \"postgres\"}' where id=6 "
    PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "update connection set options='{\"host\": \"10.240.1.1\", \"port\": 5434, \"type\": \"postgresql\", \"config\": {}, \"database\": \"postgres\", \"encoding\": \"UTF-8\", \"password\": \"postgres\", \"username\": \"postgres\"}' where id=12 "
}


# -------------- engine -----------------
ENGINE_HOME=$HS_HOME/engine-cluster
restore_engine() {
    source $ENGINE_HOME/export-cluster.sh
    echo "engine: pg_restore"
    psql postgres -f engine.back.sql
}

# ------- run -------------
restore_meta postgres
modify_connection
restore_meta hengshi_sense_internal_storage

restore_engine

results matching ""

    No results matching ""

    sense-backup.sh