From 59e37e0ccb4ce3eeb93dd8656c5bfcf3628ebeec Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Fri, 22 Dec 2023 17:38:04 +0000 Subject: [PATCH] also make sudo changes to restore --- restore.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/restore.sh b/restore.sh index 98bdbaacea..5cfb76f949 100755 --- a/restore.sh +++ b/restore.sh @@ -353,14 +353,14 @@ fi print_green 'Creating MeshCentral DB' -sudo -u postgres psql -c "CREATE DATABASE meshcentral" -sudo -u postgres psql -c "CREATE USER ${MESH_POSTGRES_USER} WITH PASSWORD '${MESH_POSTGRES_PW}'" -sudo -u postgres psql -c "ALTER ROLE ${MESH_POSTGRES_USER} SET client_encoding TO 'utf8'" -sudo -u postgres psql -c "ALTER ROLE ${MESH_POSTGRES_USER} SET default_transaction_isolation TO 'read committed'" -sudo -u postgres psql -c "ALTER ROLE ${MESH_POSTGRES_USER} SET timezone TO 'UTC'" -sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE meshcentral TO ${MESH_POSTGRES_USER}" -sudo -u postgres psql -c "ALTER DATABASE meshcentral OWNER TO ${MESH_POSTGRES_USER}" -sudo -u postgres psql -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${MESH_POSTGRES_USER}" +sudo -iu postgres psql -c "CREATE DATABASE meshcentral" +sudo -iu postgres psql -c "CREATE USER ${MESH_POSTGRES_USER} WITH PASSWORD '${MESH_POSTGRES_PW}'" +sudo -iu postgres psql -c "ALTER ROLE ${MESH_POSTGRES_USER} SET client_encoding TO 'utf8'" +sudo -iu postgres psql -c "ALTER ROLE ${MESH_POSTGRES_USER} SET default_transaction_isolation TO 'read committed'" +sudo -iu postgres psql -c "ALTER ROLE ${MESH_POSTGRES_USER} SET timezone TO 'UTC'" +sudo -iu postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE meshcentral TO ${MESH_POSTGRES_USER}" +sudo -iu postgres psql -c "ALTER DATABASE meshcentral OWNER TO ${MESH_POSTGRES_USER}" +sudo -iu postgres psql -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${MESH_POSTGRES_USER}" if [ "$FROM_MONGO" = true ]; then print_green 'Converting mesh mongo to postgres' @@ -431,14 +431,14 @@ print_green 'Restoring the trmm database' pgusername=$(grep -w USER /rmm/api/tacticalrmm/tacticalrmm/local_settings.py | sed 's/^.*: //' | sed 's/.//' | sed -r 's/.{2}$//') pgpw=$(grep -w PASSWORD /rmm/api/tacticalrmm/tacticalrmm/local_settings.py | sed 's/^.*: //' | sed 's/.//' | sed -r 's/.{2}$//') -sudo -u postgres psql -c "CREATE DATABASE tacticalrmm" -sudo -u postgres psql -c "CREATE USER ${pgusername} WITH PASSWORD '${pgpw}'" -sudo -u postgres psql -c "ALTER ROLE ${pgusername} SET client_encoding TO 'utf8'" -sudo -u postgres psql -c "ALTER ROLE ${pgusername} SET default_transaction_isolation TO 'read committed'" -sudo -u postgres psql -c "ALTER ROLE ${pgusername} SET timezone TO 'UTC'" -sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE tacticalrmm TO ${pgusername}" -sudo -u postgres psql -c "ALTER DATABASE tacticalrmm OWNER TO ${pgusername}" -sudo -u postgres psql -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${pgusername}" +sudo -iu postgres psql -c "CREATE DATABASE tacticalrmm" +sudo -iu postgres psql -c "CREATE USER ${pgusername} WITH PASSWORD '${pgpw}'" +sudo -iu postgres psql -c "ALTER ROLE ${pgusername} SET client_encoding TO 'utf8'" +sudo -iu postgres psql -c "ALTER ROLE ${pgusername} SET default_transaction_isolation TO 'read committed'" +sudo -iu postgres psql -c "ALTER ROLE ${pgusername} SET timezone TO 'UTC'" +sudo -iu postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE tacticalrmm TO ${pgusername}" +sudo -iu postgres psql -c "ALTER DATABASE tacticalrmm OWNER TO ${pgusername}" +sudo -iu postgres psql -c "GRANT USAGE, CREATE ON SCHEMA PUBLIC TO ${pgusername}" gzip -d $tmp_dir/postgres/db*.psql.gz PGPASSWORD=${pgpw} psql -h localhost -U ${pgusername} -d tacticalrmm -f $tmp_dir/postgres/db*.psql