Add some server backup scripts

This commit is contained in:
octospacc 2023-01-14 13:05:26 +01:00
parent 2333f8d9fe
commit 8e036f308c
13 changed files with 174 additions and 0 deletions

0
Makefile Normal file
View File

View File

@ -0,0 +1,11 @@
#!/bin/sh
BackupsBase="/media/Disk/Backup"
# ScriptDir="$( dirname "$( realpath "$0" )" )"
# cd "$ScriptDir"
RunDate="$(date +%F)"
cd "${BackupsBase}"
source ./.BackupSecrects.cfg

View File

@ -0,0 +1,49 @@
#!/bin/sh
# Upload a backup of the Local Cloud and of local services backups to other clouds
source ./BackupGlobals.cfg
GitPush() {
git add .
git commit -m "Auto Backup $(date)"
git push
}
#Server-Backup-Limited
#CloudDir="/home/octo/Cloud"
#cd "$CloudDir"
#TmpDir="/media/Disk/tmp/LocalToCloudBackup"
#mkdir "$TmpDir"
#find . -type f -exec ""$ScriptDir"/LocalToCloudBackup.Job" {} \;
#find . -type f -exec COMMAND 7z a -mx9 -mmt1 -p"$Password" "arc/"$i".7z" "$i" {} \;
#rclone sync -v "$CloudDir" "MEGA-octo-tutamail.com-Crypto":
#rclone sync -v "$CloudDir" "Dropbox-Union-20220407-Crypto":
#rclone sync -v "$CloudDir" "Box-Union-20220407-Crypto":
#rclone copy arc "mega octo":Backup/LocalCloud
#cd /media/Disk/Backup/Social-Notes-Articles-Backups
#git pull
#cd /Server/Bots/MastodonFeedHTML
#for Dir in @*@*.*
#do
# cp -r $Dir /media/Disk/Backup/Social-Notes-Articles-Backups/$Dir
# mv $Dir $Dir.old
#done
#cd /media/Disk/Backup/Social-Notes-Articles-Backups
#for Dir in @*@*.*
#do
# cd $Dir
# for File in *.html
# do
# 7z a -mx9 -mmt1 "$File.7z" "$File"
# done
# rm *.html
# cd ..
#done
#GitPush
date > "${BackupsBase}/Last.log"

View File

@ -0,0 +1,65 @@
#!/bin/sh
# Make local backups of the data from the hosted services
source ./BackupGlobals.cfg
SimpleBackup() {
mkdir -p "./$1"
tar cvJSf "./$1/${RunDate}.tar.xz" "/Server/$1" && \
cp "./$1/${RunDate}.tar.xz" "./$1/Latest.tar.xz"
}
# Wallabag
SimpleBackup "wallabag-data"
#Name="wallabag-data"
#mkdir -p "./${Name}"
#tar cvJSf "./${Name}/${Date}.tar.xz" "/Server/${Name}" && \
#cp "./${Name}/${Date}.tar.xz" "./${Name}/Latest.tar.xz"
#7z a -mmt1 -mx9 \
# "./${Name}/${Date}.7z" /Server/wallabag-data && \
# cp "./${Name}/${Date}.7z" "./${Name}/Latest.7z"
# FreshRSS
SimpleBackup "FreshRSS-data"
#Name="FreshRSS-data"
#mkdir -p "./${Name}"
#tar cvJSf "./${Name}/${Date}.tar.xz" "/Server/${Name}" && \
#cp "./${Name}/${Date}.tar.xz" "./${Name}/Latest.tar.xz"
#7z a -mmt1 -mx9 \
# "./${Name}/${Date}.7z" /Server/FreshRSS/data && \
# cp "./${Name}/${Date}.7z" "./${Name}/Latest.7z"
#7z a -mmt1 -mx9 \
# "./FreshRSS-data/${Date}.7z" /media/Disk/Server/docker-base/volumes/775f882852d2ca0efacd0e92426d07a1257c6ffc65aa83ce0970969c95f0fefd/_data/www/freshrss/data && \
# cp "./FreshRSS-data/${Date}.7z" ./FreshRSS-data/Latest.7z
#7z a -mx9 -mmt1 "./FreshRSS-data/$Date.7z" /Server/FreshRSS/data && cp "./FreshRSS-data/$Date.7z" ./FreshRSS-data/latest.7z
# GoToSocial
#Name="GoToSocial"
#mkdir -p "./${Name}"
#tar cvJSf "./${Name}/${Date}.tar.xz" /Server/GoToSocial.Home
# Misskey
#7z a -mx1 -mmt1 ./misskey-home.7z /Server/misskey-home
#zip -r ./misskey-home.zip /Server/misskey-home.virtual
#cd /media/Disk/Backup/Social-Notes-Articles-Backups
#git pull
#cd /Server/Bots/MastodonFeedHTML
#for Dir in @*@*.*
#do
# cp -r $Dir /media/Disk/Backup/Social-Notes-Articles-Backups/$Dir
# mv $Dir $Dir.old
#done
#cd /media/Disk/Backup/Social-Notes-Articles-Backups
#for Dir in @*@*.*
#do
# cd $Dir
# for File in *.html
# do
# 7z a -mx9 -mmt1 "$File.7z" "$File"
# done
# rm *.html
# cd ..
#done
date > "${BackupsBase}/Last.log"

49
Server/diycron Executable file
View File

@ -0,0 +1,49 @@
#!/bin/sh
# 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; }
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))); }
# Setting variables (that always have a "Job" prefix) for each job, to prevent multiple execution.
ResetJobs() {
for Job in \
1 2
do eval "Job$Job=0"
done
}
ResetJobs
while true
do
# Declaration of all cronjobs like they are normal shell commands, made easy thanks to integrated functions.
# Daily checking for if the script is working
Ifn $Job1 && If $(IsDayMin $(hm2s 5 30)) && date > /tmp/CronTest.log && Job1=1
# RSS to Misskey at HH:15 and HH:45
# If $(IsHourMin 15) || If $(IsHourMin 45) && sudo -u pi /Server/Bots/RSSToMisskey/Run.RSSToMisskey
# Downsync updated content to the sitoctt and push
# If $(IsHourMin 25) && sudo -u pi /Server/Scripts/sitoctt-Downsync.sh
# 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 && /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 && /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 && /Server/Scripts/Backup/CloudBackup.sh & # Cloud backup of the locally backed-up data
# Clean Misskey cache daily
# If $(IsDayMin $(hm2s 2 30)) && curl 'https://miss.octt.eu.org/api/admin/drive/clean-remote-files' -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:107.0) Gecko/20100101 Firefox/107.0' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: text/plain;charset=UTF-8' -H 'Referer: https://miss.octt.eu.org/' -H 'Origin: https://miss.octt.eu.org' -H 'DNT: 1' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'Connection: keep-alive' --data-raw '{"i":"TOKEN"}'
# System reboot every X days
If $(IsDayMin $(hm2s 4 30)) && test $(($(date +%s) / 86400 % 2)) = 0 && sleep 60 && reboot
#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
# 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
# Cooldown to wait at each cycle, to save on resources (Should always be less than 60 seconds!).
sleep 5
done