Update backup.sh

This commit is contained in:
dinger1986
2023-08-25 09:05:14 +01:00
committed by GitHub
parent b4ab33f25d
commit cde1a2e77a

View File

@@ -3,6 +3,87 @@ usern=$(whoami)
path=$(pwd)
echo $path
ARCH=$(uname -m)
# Identify OS
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
UPSTREAM_ID=${ID_LIKE,,}
# Fallback to ID_LIKE if ID was not 'ubuntu' or 'debian'
if [ "${UPSTREAM_ID}" != "debian" ] && [ "${UPSTREAM_ID}" != "ubuntu" ]; then
UPSTREAM_ID="$(echo ${ID_LIKE,,} | sed s/\"//g | cut -d' ' -f1)"
fi
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian, Ubuntu, etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSE-release ]; then
# Older SuSE, etc.
OS=SuSE
VER=$(cat /etc/SuSE-release)
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
OS=RedHat
VER=$(cat /etc/redhat-release)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
# Output debugging info if $DEBUG set
if [ "$DEBUG" = "true" ]; then
echo "OS: $OS"
echo "VER: $VER"
echo "UPSTREAM_ID: $UPSTREAM_ID"
exit 0
fi
# Setup prereqs for server
# Common named prereqs
PREREQ="tar"
PREREQDEB="sqlite3"
PREREQRPM="sqlite"
PREREQARCH="sqlite"
echo "Installing prerequisites"
if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ]; then
sudo apt-get update
sudo apt-get install -y ${PREREQ} ${PREREQDEB} # git
elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] ; then
# openSUSE 15.4 fails to run the relay service and hangs waiting for it
# Needs more work before it can be enabled
# || [ "${UPSTREAM_ID}" = "suse" ]
sudo yum update -y
sudo dnf install -y epel-release
sudo yum install -y ${PREREQ} ${PREREQRPM} # git
elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ]; then
sudo pacman -Syu
sudo pacman -S ${PREREQ} ${PREREQARCH}
else
echo "Unsupported OS"
# Here you could ask the user for permission to try and install anyway
# If they say yes, then do the install
# If they say no, exit the script
exit 1
fi
if [[ $* == *--schedule* ]]; then
(
crontab -l 2>/dev/null
@@ -33,7 +114,6 @@ fi
if [ ! -d /opt/rustdesk-server-backups ]; then
sudo mkdir /opt/rustdesk-server-backups
sudo chown ${usern}:${usern} /opt/rustdesk-server-backups
sudo apt install sqlite3 -y
fi
dt_now=$(date '+%Y_%m_%d__%H_%M_%S')
@@ -43,7 +123,7 @@ sysd="/etc/systemd/system"
mkdir -p ${tmp_dir}/rustdesk
cp -rf /var/lib/rustdesk-server/ ${tmp_dir}/
sqlite3 db.sqlite3 .dump > ${tmp_dir}/db_backup_file.sq3
sqlite3 /var/lib/rustdesk-server/db.sqlite3 .dump > ${tmp_dir}/db_backup_file.sql
if [[ $* == *--auto* ]]; then