fix backup/restore when OS are different
This commit is contained in:
parent
7e2295c382
commit
2526fa3c47
|
@ -1,3 +1,5 @@
|
|||
from urllib.parse import urlparse
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
@ -22,6 +24,8 @@ class Command(BaseCommand):
|
|||
self.stdout.write(settings.NATS_SERVER_VER)
|
||||
case "frontend":
|
||||
self.stdout.write(settings.CORS_ORIGIN_WHITELIST[0])
|
||||
case "webdomain":
|
||||
self.stdout.write(urlparse(settings.CORS_ORIGIN_WHITELIST[0]).netloc)
|
||||
case "djangoadmin":
|
||||
url = f"https://{settings.ALLOWED_HOSTS[0]}/{settings.ADMIN_URL}"
|
||||
self.stdout.write(url)
|
||||
|
@ -39,7 +43,7 @@ class Command(BaseCommand):
|
|||
self.stdout.write(settings.DATABASES["default"]["HOST"])
|
||||
case "dbport":
|
||||
self.stdout.write(settings.DATABASES["default"]["PORT"])
|
||||
case "meshsite" | "meshuser" | "meshtoken":
|
||||
case "meshsite" | "meshuser" | "meshtoken" | "meshdomain":
|
||||
from core.models import CoreSettings
|
||||
|
||||
core: "CoreSettings" = CoreSettings.objects.first()
|
||||
|
@ -47,6 +51,8 @@ class Command(BaseCommand):
|
|||
obj = core.mesh_site
|
||||
elif kwargs["name"] == "meshuser":
|
||||
obj = core.mesh_username
|
||||
elif kwargs["name"] == "meshdomain":
|
||||
obj = urlparse(core.mesh_site).netloc
|
||||
else:
|
||||
obj = core.mesh_token
|
||||
|
||||
|
|
|
@ -426,6 +426,7 @@ CONFIG_MGMT_CMDS = (
|
|||
"meshver",
|
||||
"natsver",
|
||||
"frontend",
|
||||
"webdomain",
|
||||
"djangoadmin",
|
||||
"setuptoolsver",
|
||||
"wheelver",
|
||||
|
@ -437,4 +438,5 @@ CONFIG_MGMT_CMDS = (
|
|||
"meshsite",
|
||||
"meshuser",
|
||||
"meshtoken",
|
||||
"meshdomain",
|
||||
)
|
||||
|
|
17
backup.sh
17
backup.sh
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_VERSION="20"
|
||||
SCRIPT_VERSION="21"
|
||||
SCRIPT_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/backup.sh'
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
|
@ -27,10 +27,6 @@ if [ $EUID -eq 0 ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
POSTGRES_USER=$(grep -w USER /rmm/api/tacticalrmm/tacticalrmm/local_settings.py | sed 's/^.*: //' | sed 's/.//' | sed -r 's/.{2}$//')
|
||||
POSTGRES_PW=$(grep -w PASSWORD /rmm/api/tacticalrmm/tacticalrmm/local_settings.py | sed 's/^.*: //' | sed 's/.//' | sed -r 's/.{2}$//')
|
||||
|
||||
|
||||
if [ ! -d /rmmbackups ]; then
|
||||
sudo mkdir /rmmbackups
|
||||
sudo chown ${USER}:${USER} /rmmbackups
|
||||
|
@ -56,6 +52,8 @@ mkdir ${tmp_dir}/systemd
|
|||
mkdir ${tmp_dir}/rmm
|
||||
mkdir ${tmp_dir}/confd
|
||||
|
||||
POSTGRES_USER=$(/rmm/api/env/bin/python /rmm/api/tacticalrmm/manage.py get_config dbuser)
|
||||
POSTGRES_PW=$(/rmm/api/env/bin/python /rmm/api/tacticalrmm/manage.py get_config dbpw)
|
||||
|
||||
pg_dump --dbname=postgresql://"${POSTGRES_USER}":"${POSTGRES_PW}"@127.0.0.1:5432/tacticalrmm | gzip -9 > ${tmp_dir}/postgres/db-${dt_now}.psql.gz
|
||||
|
||||
|
@ -64,14 +62,13 @@ mongodump --gzip --out=${tmp_dir}/meshcentral/mongo
|
|||
|
||||
sudo tar -czvf ${tmp_dir}/certs/etc-letsencrypt.tar.gz -C /etc/letsencrypt .
|
||||
|
||||
sudo tar -czvf ${tmp_dir}/nginx/etc-nginx.tar.gz -C /etc/nginx .
|
||||
for i in rmm frontend meshcentral; do
|
||||
sudo cp /etc/nginx/sites-available/${i}.conf ${tmp_dir}/nginx/
|
||||
done
|
||||
|
||||
sudo tar -czvf ${tmp_dir}/confd/etc-confd.tar.gz -C /etc/conf.d .
|
||||
|
||||
sudo cp ${sysd}/rmm.service ${sysd}/celery.service ${sysd}/celerybeat.service ${sysd}/meshcentral.service ${sysd}/nats.service ${sysd}/daphne.service ${tmp_dir}/systemd/
|
||||
if [ -f "${sysd}/nats-api.service" ]; then
|
||||
sudo cp ${sysd}/nats-api.service ${tmp_dir}/systemd/
|
||||
fi
|
||||
sudo cp ${sysd}/rmm.service ${sysd}/celery.service ${sysd}/celerybeat.service ${sysd}/meshcentral.service ${sysd}/nats.service ${sysd}/daphne.service ${sysd}/nats-api.service ${tmp_dir}/systemd/
|
||||
|
||||
cat /rmm/api/tacticalrmm/tacticalrmm/private/log/django_debug.log | gzip -9 > ${tmp_dir}/rmm/debug.log.gz
|
||||
cp /rmm/api/tacticalrmm/tacticalrmm/local_settings.py ${tmp_dir}/rmm/
|
||||
|
|
55
restore.sh
55
restore.sh
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_VERSION="44"
|
||||
SCRIPT_VERSION="45"
|
||||
SCRIPT_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/restore.sh'
|
||||
|
||||
sudo apt update
|
||||
|
@ -139,13 +139,51 @@ echo "${nginxrepo}" | sudo tee /etc/apt/sources.list.d/nginx.list > /dev/null
|
|||
sudo apt update
|
||||
sudo apt install -y nginx
|
||||
sudo systemctl stop nginx
|
||||
sudo rm -rf /etc/nginx
|
||||
sudo mkdir /etc/nginx
|
||||
sudo tar -xzf $tmp_dir/nginx/etc-nginx.tar.gz -C /etc/nginx
|
||||
|
||||
rmmdomain=$(grep server_name /etc/nginx/sites-available/rmm.conf | grep -v 301 | head -1 | tr -d " \t" | sed 's/.*server_name//' | tr -d ';')
|
||||
frontenddomain=$(grep server_name /etc/nginx/sites-available/frontend.conf | grep -v 301 | head -1 | tr -d " \t" | sed 's/.*server_name//' | tr -d ';')
|
||||
meshdomain=$(grep server_name /etc/nginx/sites-available/meshcentral.conf | grep -v 301 | head -1 | tr -d " \t" | sed 's/.*server_name//' | tr -d ';')
|
||||
nginxdefaultconf='/etc/nginx/nginx.conf'
|
||||
|
||||
nginxconf="$(cat << EOF
|
||||
worker_rlimit_nofile 1000000;
|
||||
user www-data;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
include /etc/nginx/modules-enabled/*.conf;
|
||||
|
||||
events {
|
||||
worker_connections 4096;
|
||||
}
|
||||
|
||||
http {
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
types_hash_max_size 2048;
|
||||
server_names_hash_bucket_size 64;
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_prefer_server_ciphers on;
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
gzip on;
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
EOF
|
||||
)"
|
||||
echo "${nginxconf}" | sudo tee $nginxdefaultconf > /dev/null
|
||||
|
||||
for i in sites-available sites-enabled; do
|
||||
sudo mkdir -p /etc/nginx/$i
|
||||
done
|
||||
|
||||
for i in rmm frontend meshcentral; do
|
||||
sudo cp ${tmp_dir}/nginx/${i}.conf /etc/nginx/sites-available/
|
||||
sudo ln -s /etc/nginx/sites-available/${i}.conf /etc/nginx/sites-enabled/${i}.conf
|
||||
done
|
||||
|
||||
rmmdomain=$(/rmm/api/env/bin/python /rmm/api/tacticalrmm/manage.py get_config api)
|
||||
frontenddomain=$(/rmm/api/env/bin/python /rmm/api/tacticalrmm/manage.py get_config webdomain)
|
||||
meshdomain=$(/rmm/api/env/bin/python /rmm/api/tacticalrmm/manage.py get_config meshdomain)
|
||||
|
||||
|
||||
print_green 'Restoring hosts file'
|
||||
|
@ -218,8 +256,7 @@ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add
|
|||
echo "$mongodb_repo" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
|
||||
sudo apt update
|
||||
sudo apt install -y mongodb-org
|
||||
sudo systemctl enable mongod
|
||||
sudo systemctl restart mongod
|
||||
sudo systemctl enable --now mongod
|
||||
sleep 5
|
||||
mongorestore --gzip $tmp_dir/meshcentral/mongo
|
||||
|
||||
|
|
Loading…
Reference in New Issue