feat: support restore data to postgresql database
This commit is contained in:
3 files changed
+32
-10
No files matched your search
@@ -36,13 +36,6 @@ if [[ "$1" == "restore" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
function configure_postgresql() {
|
||||
if [[ "${DB_TYPE}" == "POSTGRESQL" ]]; then
|
||||
echo "${PG_HOST}:${PG_PORT}:${PG_DBNAME}:${PG_USERNAME}:${PG_PASSWORD}" > ~/.pgpass
|
||||
chmod 0600 ~/.pgpass
|
||||
fi
|
||||
}
|
||||
|
||||
function configure_timezone() {
|
||||
ln -sf "/usr/share/zoneinfo/${TIMEZONE}" "${LOCALTIME_FILE}"
|
||||
}
|
||||
|
||||
@@ -142,6 +142,18 @@ function send_ping() {
|
||||
fi
|
||||
}
|
||||
|
||||
########################################
|
||||
# Configure PostgreSQL password file.
|
||||
# Arguments:
|
||||
# None
|
||||
########################################
|
||||
function configure_postgresql() {
|
||||
if [[ "${DB_TYPE}" == "POSTGRESQL" ]]; then
|
||||
echo "${PG_HOST}:${PG_PORT}:${PG_DBNAME}:${PG_USERNAME}:${PG_PASSWORD}" > ~/.pgpass
|
||||
chmod 0600 ~/.pgpass
|
||||
fi
|
||||
}
|
||||
|
||||
########################################
|
||||
# Export variables from .env file.
|
||||
# Arguments:
|
||||
|
||||
+20
-3
@@ -39,7 +39,7 @@ function restore_zip() {
|
||||
fi
|
||||
|
||||
# get restore db file
|
||||
FIND_FILE_DB="$( basename "$(ls ${RESTORE_EXTRACT_DIR}/db.*.sqlite3 2>/dev/null)" )"
|
||||
FIND_FILE_DB="$( basename "$(ls ${RESTORE_EXTRACT_DIR}/db.*.* 2>/dev/null)" )"
|
||||
RESTORE_FILE_DB="${FIND_FILE_DB:-}"
|
||||
|
||||
# get restore config file
|
||||
@@ -63,7 +63,7 @@ function restore_zip() {
|
||||
restore_file
|
||||
}
|
||||
|
||||
function restore_db() {
|
||||
function restore_db_sqlite() {
|
||||
color blue "restore vaultwarden sqlite database"
|
||||
|
||||
cp -f "${RESTORE_FILE_DB}" "${DATA_DB}"
|
||||
@@ -75,6 +75,18 @@ function restore_db() {
|
||||
fi
|
||||
}
|
||||
|
||||
function restore_db_postgresql() {
|
||||
color blue "restore vaultwarden sqlite database"
|
||||
|
||||
pg_restore -h "${PG_HOST}" -p "${PG_PORT}" -d "${PG_DBNAME}" -U "${PG_USERNAME}" -c "${RESTORE_FILE_DB}"
|
||||
|
||||
if [[ $? == 0 ]]; then
|
||||
color green "restore vaultwarden postgresql database successful"
|
||||
else
|
||||
color red "restore vaultwarden postgresql database failed"
|
||||
fi
|
||||
}
|
||||
|
||||
function restore_config() {
|
||||
color blue "restore vaultwarden config"
|
||||
|
||||
@@ -190,7 +202,10 @@ function restore_file() {
|
||||
fi
|
||||
|
||||
if [[ -n "${RESTORE_FILE_DB}" ]]; then
|
||||
restore_db
|
||||
case "${DB_TYPE}" in
|
||||
SQLITE) restore_db_sqlite ;;
|
||||
POSTGRESQL) restore_db_postgresql ;;
|
||||
esac
|
||||
fi
|
||||
if [[ -n "${RESTORE_FILE_CONFIG}" ]]; then
|
||||
restore_config
|
||||
@@ -276,6 +291,8 @@ function restore() {
|
||||
done
|
||||
|
||||
init_env_dir
|
||||
init_env_db
|
||||
configure_postgresql
|
||||
check_empty_input
|
||||
check_data_dir_exist
|
||||
|
||||
|
||||
Reference in new issue
Block a user