2020-07-17 05:02:25 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-10-30 03:55:50 +00:00
|
|
|
SCRIPT_VERSION="2"
|
2020-10-18 23:45:21 +00:00
|
|
|
SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/develop/backup.sh'
|
|
|
|
|
|
|
|
GREEN='\033[0;32m'
|
|
|
|
YELLOW='\033[1;33m'
|
|
|
|
BLUE='\033[0;34m'
|
|
|
|
RED='\033[0;31m'
|
|
|
|
NC='\033[0m'
|
|
|
|
|
|
|
|
TMP_FILE=$(mktemp -p "" "rmmbackup_XXXXXXXXXX")
|
|
|
|
curl -s -L "${SCRIPT_URL}" > ${TMP_FILE}
|
|
|
|
NEW_VER=$(grep "^SCRIPT_VERSION" "$TMP_FILE" | awk -F'[="]' '{print $3}')
|
|
|
|
|
|
|
|
if [ "${SCRIPT_VERSION}" -ne "${NEW_VER}" ]; then
|
|
|
|
printf >&2 "${YELLOW}A newer version of this backup script is available.${NC}\n"
|
|
|
|
printf >&2 "${YELLOW}Please download the latest version from ${GREEN}${SCRIPT_URL}${YELLOW} and re-run.${NC}\n"
|
|
|
|
rm -f $TMP_FILE
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-10-17 04:41:47 +00:00
|
|
|
if [ $EUID -eq 0 ]; then
|
|
|
|
echo -ne "\033[0;31mDo NOT run this script as root. Exiting.\e[0m\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-10-18 23:45:21 +00:00
|
|
|
#####################################################
|
|
|
|
|
|
|
|
POSTGRES_USER="changeme"
|
|
|
|
POSTGRES_PW="hunter2"
|
|
|
|
|
|
|
|
#####################################################
|
2020-10-17 04:41:47 +00:00
|
|
|
|
2020-07-17 05:02:25 +00:00
|
|
|
if [ ! -d /rmmbackups ]; then
|
|
|
|
sudo mkdir /rmmbackups
|
|
|
|
sudo chown ${USER}:${USER} /rmmbackups
|
|
|
|
fi
|
|
|
|
|
|
|
|
dt_now=$(date '+%Y_%m_%d__%H_%M_%S')
|
|
|
|
tmp_dir=$(mktemp -d -t tacticalrmm-XXXXXXXXXXXXXXXXXXXXX)
|
|
|
|
sysd="/etc/systemd/system"
|
|
|
|
|
|
|
|
mkdir -p ${tmp_dir}/meshcentral/mongo
|
|
|
|
mkdir ${tmp_dir}/postgres
|
|
|
|
mkdir ${tmp_dir}/salt
|
|
|
|
mkdir ${tmp_dir}/certs
|
|
|
|
mkdir ${tmp_dir}/nginx
|
|
|
|
mkdir ${tmp_dir}/systemd
|
|
|
|
mkdir ${tmp_dir}/rmm
|
2020-09-10 17:09:26 +00:00
|
|
|
mkdir ${tmp_dir}/confd
|
2020-07-17 05:02:25 +00:00
|
|
|
|
|
|
|
|
2020-10-30 03:55:50 +00:00
|
|
|
pg_dump --dbname=postgresql://"${POSTGRES_USER}":"${POSTGRES_PW}"@127.0.0.1:5432/tacticalrmm | gzip -9 > ${tmp_dir}/postgres/db-${dt_now}.psql.gz
|
2020-07-17 05:02:25 +00:00
|
|
|
|
|
|
|
tar -czvf ${tmp_dir}/meshcentral/mesh.tar.gz --exclude=/meshcentral/node_modules /meshcentral
|
|
|
|
mongodump --gzip --out=${tmp_dir}/meshcentral/mongo
|
|
|
|
|
|
|
|
sudo tar -czvf ${tmp_dir}/salt/etc-salt.tar.gz -C /etc/salt .
|
|
|
|
tar -czvf ${tmp_dir}/salt/srv-salt.tar.gz -C /srv/salt .
|
|
|
|
|
2020-10-18 23:45:21 +00:00
|
|
|
if [ -d "/certs" ]; then
|
|
|
|
sudo tar -czvf ${tmp_dir}/certs/certs.tar.gz -C /certs .
|
|
|
|
else
|
|
|
|
sudo tar -czvf ${tmp_dir}/certs/etc-letsencrypt.tar.gz -C /etc/letsencrypt .
|
|
|
|
fi
|
|
|
|
|
2020-07-17 05:02:25 +00:00
|
|
|
|
|
|
|
sudo tar -czvf ${tmp_dir}/nginx/etc-nginx.tar.gz -C /etc/nginx .
|
|
|
|
|
2020-09-10 17:09:26 +00:00
|
|
|
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}/celery-winupdate.service ${sysd}/meshcentral.service ${tmp_dir}/systemd/
|
2020-07-17 05:02:25 +00:00
|
|
|
|
|
|
|
cat /rmm/api/tacticalrmm/tacticalrmm/private/log/debug.log | gzip -9 > ${tmp_dir}/rmm/debug.log.gz
|
|
|
|
cp /rmm/api/tacticalrmm/tacticalrmm/local_settings.py /rmm/api/tacticalrmm/app.ini ${tmp_dir}/rmm/
|
|
|
|
cp /rmm/web/.env ${tmp_dir}/rmm/env
|
2020-10-17 04:41:47 +00:00
|
|
|
cp /rmm/api/tacticalrmm/tacticalrmm/private/exe/mesh*.exe ${tmp_dir}/rmm/
|
2020-07-17 05:02:25 +00:00
|
|
|
|
|
|
|
tar -cf /rmmbackups/rmm-backup-${dt_now}.tar -C ${tmp_dir} .
|
|
|
|
|
2020-10-17 04:41:47 +00:00
|
|
|
rm -rf ${tmp_dir}
|
|
|
|
|
|
|
|
echo -ne "${GREEN}Backup saved to /rmmbackups/rmm-backup-${dt_now}.tar${NC}\n"
|