From a7ed28ff0281b57a46569be55b66fd7c026830d0 Mon Sep 17 00:00:00 2001 From: octospacc Date: Tue, 29 Aug 2023 17:40:07 +0200 Subject: [PATCH] New server --- Lib.sh | 13 +++++---- Server/Repo.Update.sh | 10 ++++--- .../Server/Scripts/Backup/BackupGlobals.cfg | 3 +- .../Server/Scripts/Backup/CloudBackup.sh | 26 +++++++++-------- .../Scripts/Backup/ExternalDataBackup.sh | 0 .../Server/Scripts/Backup/ServerDataBackup.sh | 25 +++++++++++------ .../Server/Scripts/OneShot.AfterBoot.sh | 0 .../{ => Main}/Server/Scripts/RenewCerts.sh | 0 .../Root/{ => Main}/Server/Start/bittorrentd | 0 .../Transfers/aria2/Conf/Server.conf | 0 Server/Root/etc/diycron | 28 ++++++++++--------- .../Root/etc/systemd/system/diycron.service | 1 - 12 files changed, 61 insertions(+), 45 deletions(-) rename Server/Root/{ => Main}/Server/Scripts/Backup/BackupGlobals.cfg (92%) mode change 100644 => 100755 rename Server/Root/{ => Main}/Server/Scripts/Backup/CloudBackup.sh (86%) rename Server/Root/{ => Main}/Server/Scripts/Backup/ExternalDataBackup.sh (100%) rename Server/Root/{ => Main}/Server/Scripts/Backup/ServerDataBackup.sh (73%) rename Server/Root/{ => Main}/Server/Scripts/OneShot.AfterBoot.sh (100%) rename Server/Root/{ => Main}/Server/Scripts/RenewCerts.sh (100%) rename Server/Root/{ => Main}/Server/Start/bittorrentd (100%) rename Server/Root/{ => Main}/Transfers/aria2/Conf/Server.conf (100%) diff --git a/Lib.sh b/Lib.sh index fd57d31..337f58a 100644 --- a/Lib.sh +++ b/Lib.sh @@ -36,11 +36,14 @@ CpSufx(){ } cpfile(){ - echo "$1" - rm -rf "./$1" && \ - mkdir -p "./$1" && \ - rm -rf "./$1" && \ - cp --no-target-directory "${ScopePath}$1" "./$1" + if [ -f "${ScopePath}$1" ] + then + echo "$1" + rm -rf "./$1" && \ + mkdir -p "./$1" && \ + rm -rf "./$1" && \ + cp --no-target-directory "${ScopePath}$1" "./$1" + fi } cpdir(){ diff --git a/Server/Repo.Update.sh b/Server/Repo.Update.sh index 509b349..9ce00e0 100755 --- a/Server/Repo.Update.sh +++ b/Server/Repo.Update.sh @@ -21,11 +21,13 @@ mkcd ./Root CpItem etc/nginx/nginx.conf CpSufx "etc/nginx/sites-available/*." conf old CpItem etc/tor/torrc - CpSufx "Server/Scripts/Backup/*." sh cfg - CpItem Server/Scripts/OneShot.AfterBoot.sh + CpSufx "Main/Server/Scripts/Backup/*." sh cfg + CpSufx "Main/Server/Scripts/Interactive/*." sh + CpItem Main/Server/Scripts/OneShot.AfterBoot.sh + CpItem Main/Server/Scripts/RenewCerts.sh - CpItem Server/Start/bittorrentd - CpItem Transfers/aria2/Conf + CpItem Main/Server/Start/bittorrentd + CpItem Main/Transfers/aria2/Conf cd .. diff --git a/Server/Root/Server/Scripts/Backup/BackupGlobals.cfg b/Server/Root/Main/Server/Scripts/Backup/BackupGlobals.cfg old mode 100644 new mode 100755 similarity index 92% rename from Server/Root/Server/Scripts/Backup/BackupGlobals.cfg rename to Server/Root/Main/Server/Scripts/Backup/BackupGlobals.cfg index 7e5df38..378513b --- a/Server/Root/Server/Scripts/Backup/BackupGlobals.cfg +++ b/Server/Root/Main/Server/Scripts/Backup/BackupGlobals.cfg @@ -1,6 +1,7 @@ #!/bin/sh -BackupsBase="/media/Disk/Backup" +BackupsBase=/Main/Backup +#BackupsBase="/media/Disk/Backup" # ScriptDir="$( dirname "$( realpath "$0" )" )" # cd "$ScriptDir" diff --git a/Server/Root/Server/Scripts/Backup/CloudBackup.sh b/Server/Root/Main/Server/Scripts/Backup/CloudBackup.sh similarity index 86% rename from Server/Root/Server/Scripts/Backup/CloudBackup.sh rename to Server/Root/Main/Server/Scripts/Backup/CloudBackup.sh index ee7d6f3..b489191 100755 --- a/Server/Root/Server/Scripts/Backup/CloudBackup.sh +++ b/Server/Root/Main/Server/Scripts/Backup/CloudBackup.sh @@ -24,27 +24,28 @@ BackPathCrypt() { } ServerBackupLimited(){ - cd ./Server-Backup-Limited + EchoExec cd ./Server-Backup-Limited #BackPathCrypt "Invidious-User" "${BackupKey_Git_Invidious}" ".7z" #BackPathCrypt "wallabag-data" "${BackupKey_Git_wallabag}" BackPathCrypt FreshRSS "${BackupKey_Git_FreshRSS}" #BackPathCrypt "FreshRSS-data" "${BackupKey_Git_FreshRSS}" #BackPathCrypt "shiori-data" "${BackupKey_Git_Shiori}" + BackPathCrypt n8n-data "${BackupKey_Git_n8n}" # "${BackupKey_Git_aria2}" ".7z" GitPush - cd .. + EchoExec cd .. } ArticlesBackupPrivate(){ - cd ./Articles-Backup-Private + EchoExec cd ./Articles-Backup-Private EchoExec rm -rf ./shiori-data EchoExec cp -rp "../shiori-data/Latest.d" "./shiori-data" GitPush - cd .. + EchoExec cd .. } -SpaccBbsBackup(){ - cd ./SpaccBBS-Backup-phpBB-2023 +DoSpaccBbsBackup(){ + EchoExec cd ./SpaccBBS-Backup-phpBB-2023 EchoExec rm -rf ./SpaccBBS || true EchoExec cp -rp ../SpaccBBS/Latest.d ./SpaccBBS EchoExec cp ../SpaccBBS/Db.Latest.sql.tar.xz ./Db.sql.tar.xz @@ -55,14 +56,15 @@ SpaccBbsBackup(){ ; do ccencryptNow "$File" "$BackupKey_Git_SpaccBBS" done GitPush - cd .. + EchoExec cd .. } -SpaccBbsBackup(){ +DoSpaccCraftBackup(){ McServer="SpaccCraft" McEdition="Beta-1.7.3" McGit="spacccraft-b1.7.3-backup4" - DestPath="${BackupsBase}/${McServer}/${McGit}" + DestPath="${BackupsBase}/${McGit}" + #DestPath="${BackupsBase}/${McServer}/${McGit}" if [ -d "${DestPath}" ] then #cd "/Server/${McServer}" @@ -76,9 +78,9 @@ SpaccBbsBackup(){ ServerBackupLimited ArticlesBackupPrivate -SpaccBbsBackup -SpaccCraftBackup -GitPullPushPath "/Cloud/Repos/Personal-Game-Saves" +DoSpaccBbsBackup +DoSpaccCraftBackup +#GitPullPushPath "/Cloud/Repos/Personal-Game-Saves" #GitPullPushPath "/media/Disk/Configs" #CloudDir="/home/octo/Cloud" diff --git a/Server/Root/Server/Scripts/Backup/ExternalDataBackup.sh b/Server/Root/Main/Server/Scripts/Backup/ExternalDataBackup.sh similarity index 100% rename from Server/Root/Server/Scripts/Backup/ExternalDataBackup.sh rename to Server/Root/Main/Server/Scripts/Backup/ExternalDataBackup.sh diff --git a/Server/Root/Server/Scripts/Backup/ServerDataBackup.sh b/Server/Root/Main/Server/Scripts/Backup/ServerDataBackup.sh similarity index 73% rename from Server/Root/Server/Scripts/Backup/ServerDataBackup.sh rename to Server/Root/Main/Server/Scripts/Backup/ServerDataBackup.sh index 709db02..ae9ef72 100755 --- a/Server/Root/Server/Scripts/Backup/ServerDataBackup.sh +++ b/Server/Root/Main/Server/Scripts/Backup/ServerDataBackup.sh @@ -16,23 +16,30 @@ SimpleBackup(){ #cp "./$1/${RunDate}.tar.xz" "./$1/Latest.tar.xz" EchoExec rm "./$1/Latest.tar.xz" || true EchoExec rm -rf "./$1/Latest.d" || true - EchoExec cp -rp "/Server/$2/$1" "./$1/Latest.d" + EchoExec cp -rp "/Main/Server/$2/$1" "./$1/Latest.d" SimpleCompress "./$1/${RunDate}" "./$1/Latest.d" #cp -v "./$1/${RunDate}.tar.xz" "./$1/Latest.tar.xz" EchoExec ln -s "./${RunDate}.tar.xz" "./$1/Latest.tar.xz" } +DoBackupShiori(){ + SimpleBackup shiori-data Shiori + rm -v ./shiori-data/Latest.d/archive/* || true +} + +DoBackupSpaccBBS(){ + SimpleBackup SpaccBBS www + lxc-attach Debian2023 -- sh -c "mariadb-dump phpBB > ${PWD}/SpaccBBS/Db.Latest.sql" + SimpleCompress "./SpaccBBS/Db.${RunDate}.sql" ./SpaccBBS/Db.Latest.sql + EchoExec ln -s "./Db.${RunDate}.sql.tar.xz" ./SpaccBBS/Db.Latest.sql.tar.xz +} + #SimpleBackup "wallabag-data" #SimpleBackup "FreshRSS-data" SimpleBackup FreshRSS www - -SimpleBackup shiori-data Shiori -rm -v ./shiori-data/Latest.d/archive/* || true - -SimpleBackup SpaccBBS www -EchoExec mariadb-dump phpBB > ./SpaccBBS/Db.Latest.sql -SimpleCompress "./SpaccBBS/Db.${RunDate}.sql" ./SpaccBBS/Db.Latest.sql -EchoExec ln -s "./Db.${RunDate}.sql.tar.xz" ./SpaccBBS/Db.Latest.sql.tar.xz +SimpleBackup n8n-data +DoBackupShiori +DoBackupSpaccBBS # GoToSocial #Name="GoToSocial" diff --git a/Server/Root/Server/Scripts/OneShot.AfterBoot.sh b/Server/Root/Main/Server/Scripts/OneShot.AfterBoot.sh similarity index 100% rename from Server/Root/Server/Scripts/OneShot.AfterBoot.sh rename to Server/Root/Main/Server/Scripts/OneShot.AfterBoot.sh diff --git a/Server/Root/Server/Scripts/RenewCerts.sh b/Server/Root/Main/Server/Scripts/RenewCerts.sh similarity index 100% rename from Server/Root/Server/Scripts/RenewCerts.sh rename to Server/Root/Main/Server/Scripts/RenewCerts.sh diff --git a/Server/Root/Server/Start/bittorrentd b/Server/Root/Main/Server/Start/bittorrentd similarity index 100% rename from Server/Root/Server/Start/bittorrentd rename to Server/Root/Main/Server/Start/bittorrentd diff --git a/Server/Root/Transfers/aria2/Conf/Server.conf b/Server/Root/Main/Transfers/aria2/Conf/Server.conf similarity index 100% rename from Server/Root/Transfers/aria2/Conf/Server.conf rename to Server/Root/Main/Transfers/aria2/Conf/Server.conf diff --git a/Server/Root/etc/diycron b/Server/Root/etc/diycron index 95a7487..6f09820 100755 --- a/Server/Root/etc/diycron +++ b/Server/Root/etc/diycron @@ -2,13 +2,15 @@ # diycron: Script to be running (as a root daemon) as a (non-conflicting) cron alternative which simply works. # Note: Except when required by the shell, we use 0=false, 1=true for internal commands, for consistency. -If() { test "$1" = 1 && return 0 || return 1; } -Ifn() { test "$1" = 0 && return 0 || return 1; } +If(){ test "$1" = 1 && return 0 || return 1 ;} +Ifn(){ test "$1" = 0 && return 0 || return 1 ;} -GetDaySeconds() { echo "$(date -d "1970-01-01 UTC $(date +%T)" +%s)"; } -IsDayMin() { test $(($(GetDaySeconds)>$1)) = 1 && test $(($(GetDaySeconds)<$1+60)) = 1 && echo 1 || echo 0; } -IsHourMin() { test "$1" = "$(date +%M)" && echo 1 || echo 0; } -hm2s() { echo $((($1*60*60) + ($2*60))); } +GetDaySeconds(){ echo "$(date -d "1970-01-01 UTC $(date +%T)" +%s)" ;} +IsDayMin(){ [ "$(GetDaySeconds)" -gt "$1" ] && [ "$(GetDaySeconds)" -lt "$(($1 + 60))" ] && echo 1 || echo 0 ;} +IsHourMin(){ [ "$1" = "$(date +%M)" ] && echo 1 || echo 0 ;} +hm2s(){ echo $((($1*60*60) + ($2*60))) ;} + +Do(){ echo "Running: $@" && $@ ;} # Setting variables (that always have a "Job" prefix) for each job, to prevent multiple execution. ResetJobs() { @@ -21,7 +23,7 @@ ResetJobs() { echo "------------------------------------------" echo "[ $(date "+%F | %T") ] diycron started." -set -x # Enable command echo +#set -x # Enable command echo ResetJobs while true @@ -29,19 +31,19 @@ do # Inside here, declaration of all cronjobs like normal shell commands, made easy thanks to integrated functions. # Trinity rotation backup system: each of the following scripts is executed every 3 days, in a rotation where at least 1 script runs every night at 3:00 - Ifn $Job2 && If $(IsDayMin $(hm2s 3 0)) && test $(($(date +%s) / 86400 % 3)) = 0 && Job2=1 && sleep 60 && /Server/Scripts/Backup/ExternalDataBackup.sh #& # Local backup of external data - Ifn $Job2 && If $(IsDayMin $(hm2s 3 0)) && test $(($(date +%s) / 86400 % 3)) = 1 && Job2=1 && sleep 60 && /Server/Scripts/Backup/ServerDataBackup.sh #& # Big backup of local services data - Ifn $Job2 && If $(IsDayMin $(hm2s 3 0)) && test $(($(date +%s) / 86400 % 3)) = 2 && Job2=1 && sleep 60 && /Server/Scripts/Backup/CloudBackup.sh #& # Cloud backup of the locally backed-up data + Ifn $Job2 && If $(IsDayMin $(hm2s 3 0)) && test $(($(date +%s) / 86400 % 3)) = 0 && Job2=1 && sleep 60 && Do sh /Main/Server/Scripts/Backup/ExternalDataBackup.sh #& # Local backup of external data + Ifn $Job2 && If $(IsDayMin $(hm2s 3 0)) && test $(($(date +%s) / 86400 % 3)) = 1 && Job2=1 && sleep 60 && Do sh /Main/Server/Scripts/Backup/ServerDataBackup.sh #& # Big backup of local services data + Ifn $Job2 && If $(IsDayMin $(hm2s 3 0)) && test $(($(date +%s) / 86400 % 3)) = 2 && Job2=1 && sleep 60 && Do sh /Main/Server/Scripts/Backup/CloudBackup.sh #& # Cloud backup of the locally backed-up data # System reboot every X days at 4:30 AM #If $(IsDayMin $(hm2s 4 30)) && test $(($(date +%s) / 86400 % 2)) = 0 && sleep 60 && reboot # System reboot every 2 days (every even day) - If $(IsDayMin $(hm2s 4 30)) && sleep 60 && reboot # System reboot every night + # If $(IsDayMin $(hm2s 4 30)) && sleep 60 && reboot # System reboot every night # Try to renew SSL certs every 5 days at 4 AM - Ifn $JobCerts && If $(IsDayMin $(hm2s 4 0)) && test $(($(date +%s) / 86400 % 9)) = 0 && JobCerts=1 && sleep 60 && /Server/Scripts/RenewCerts.sh + Ifn $JobCerts && If $(IsDayMin $(hm2s 4 0)) && test $(($(date +%s) / 86400 % 9)) = 0 && JobCerts=1 && sleep 60 && Do lxc-attach Debian2023 sh /Main/Server/Scripts/RenewCerts.sh # Status of all jobs is reset at one time of the day, before or after all execute or have executed (in time). - If $(IsDayMin $(hm2s 0 0)) && ResetJobs + If $(IsDayMin $(hm2s 0 0)) && Do ResetJobs # Cooldown to wait at each cycle, to save on resources (Should always be less than 60 seconds!). sleep 5 done diff --git a/Server/Root/etc/systemd/system/diycron.service b/Server/Root/etc/systemd/system/diycron.service index 3b09875..cd624d5 100644 --- a/Server/Root/etc/systemd/system/diycron.service +++ b/Server/Root/etc/systemd/system/diycron.service @@ -1,7 +1,6 @@ [Unit] Description=diycron After=network.target -StartLimitIntervalSec=0 [Service] Type=simple Restart=always