mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-03 06:28:06 +01:00
Add clair data migration in DB migrator
This commit is contained in:
parent
7254b438ca
commit
c7a54e115c
@ -23,6 +23,7 @@ set -e
|
||||
ISMYSQL=false
|
||||
ISPGSQL=false
|
||||
ISNOTARY=false
|
||||
ISCLAIR=false
|
||||
|
||||
cur_version=""
|
||||
PGSQL_USR="postgres"
|
||||
@ -45,6 +46,10 @@ function init {
|
||||
ISPGSQL=true
|
||||
fi
|
||||
|
||||
if [ -d "/clair-db" ]; then
|
||||
ISCLAIR=true
|
||||
fi
|
||||
|
||||
if [ $ISMYSQL == false ] && [ $ISPGSQL == false ]; then
|
||||
echo "No database has been mounted for the migration. Use '-v' to set it in 'docker run'."
|
||||
exit 1
|
||||
@ -65,7 +70,11 @@ function init {
|
||||
fi
|
||||
|
||||
if [ $ISPGSQL == true ]; then
|
||||
launch_pgsql $PGSQL_USR
|
||||
if [ $ISCLAIR == true ]; then
|
||||
launch_pgsql $PGSQL_USR "/clair-db"
|
||||
else
|
||||
launch_pgsql $PGSQL_USR
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@ -130,6 +139,8 @@ function validate {
|
||||
function upgrade {
|
||||
if [ $ISNOTARY == true ];then
|
||||
up_notary $PGSQL_USR
|
||||
elif [ $ISCLAIR == true ];then
|
||||
up_clair $PGSQL_USR
|
||||
else
|
||||
up_harbor $1
|
||||
fi
|
||||
|
@ -80,3 +80,14 @@ EOF
|
||||
stop_pgsql $1
|
||||
fi
|
||||
}
|
||||
|
||||
function up_clair {
|
||||
# clair DB info: user: 'postgres' database: 'postgres'
|
||||
pg_dump -U postgres postgres > /harbor-migration/db/schema/clair.pgsql
|
||||
stop_pgsql postgres "/clair-db"
|
||||
|
||||
# it's harbor DB on pgsql.
|
||||
launch_pgsql $1
|
||||
psql -U $1 -f /harbor-migration/db/schema/clair.pgsql
|
||||
stop_pgsql $1
|
||||
}
|
@ -41,16 +41,20 @@ if [ "${1:0:1}" = '-' ]; then
|
||||
fi
|
||||
|
||||
function launch_pgsql {
|
||||
local pg_data=$2
|
||||
if [ -z $2 ]; then
|
||||
pg_data=$PGDATA
|
||||
fi
|
||||
|
||||
if [ "$1" = 'postgres' ]; then
|
||||
chown -R postgres:postgres $PGDATA
|
||||
chown -R postgres:postgres $pg_data
|
||||
# look specifically for PG_VERSION, as it is expected in the DB dir
|
||||
if [ ! -s "$PGDATA/PG_VERSION" ]; then
|
||||
if [ ! -s "$pg_data/PG_VERSION" ]; then
|
||||
file_env 'POSTGRES_INITDB_ARGS'
|
||||
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
|
||||
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
|
||||
fi
|
||||
su - $1 -c "initdb -D $PGDATA -U postgres -E UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 $POSTGRES_INITDB_ARGS"
|
||||
su - $1 -c "initdb -D $pg_data -U postgres -E UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 $POSTGRES_INITDB_ARGS"
|
||||
# check password first so we can output the warning before postgres
|
||||
# messes it up
|
||||
file_env 'POSTGRES_PASSWORD'
|
||||
@ -66,10 +70,10 @@ function launch_pgsql {
|
||||
{
|
||||
echo
|
||||
echo "host all all all $authMethod"
|
||||
} >> "$PGDATA/pg_hba.conf"
|
||||
} >> "$pg_data/pg_hba.conf"
|
||||
# internal start of server in order to allow set-up using psql-client
|
||||
# does not listen on external TCP/IP and waits until start finishes
|
||||
su - $1 -c "pg_ctl -D \"$PGDATA\" -o \"-c listen_addresses='localhost'\" -w start"
|
||||
su - $1 -c "pg_ctl -D \"$pg_data\" -o \"-c listen_addresses='localhost'\" -w start"
|
||||
|
||||
file_env 'POSTGRES_USER' 'postgres'
|
||||
file_env 'POSTGRES_DB' "$POSTGRES_USER"
|
||||
@ -107,19 +111,23 @@ EOSQL
|
||||
done
|
||||
|
||||
#PGUSER="${PGUSER:-postgres}" \
|
||||
#su - $1 -c "pg_ctl -D \"$PGDATA\" -m fast -w stop"
|
||||
#su - $1 -c "pg_ctl -D \"$pg_data\" -m fast -w stop"
|
||||
|
||||
echo
|
||||
echo 'PostgreSQL init process complete; ready for start up.'
|
||||
echo
|
||||
else
|
||||
su - $PGSQL_USR -c "pg_ctl -D \"$PGDATA\" -o \"-c listen_addresses='localhost'\" -w start"
|
||||
su - $PGSQL_USR -c "pg_ctl -D \"$pg_data\" -o \"-c listen_addresses='localhost'\" -w start"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function stop_pgsql {
|
||||
su - $1 -c "pg_ctl -D \"/var/lib/postgresql/data\" -w stop"
|
||||
local pg_data=$2
|
||||
if [ -z $2 ]; then
|
||||
pg_data=$PGDATA
|
||||
fi
|
||||
su - $1 -c "pg_ctl -D \"$pg_data\" -w stop"
|
||||
}
|
||||
|
||||
function get_version_pgsql {
|
||||
|
Loading…
Reference in New Issue
Block a user