From 9b6e4b4c4c0bb3df73d2f4a439d159b0f6e17662 Mon Sep 17 00:00:00 2001 From: octospacc Date: Tue, 31 Jan 2023 09:48:04 +0100 Subject: [PATCH] Backup Scripts --- Server/.Repo.Update.sh | 7 +++++++ Server/Scripts/Backup/BackupGlobals.cfg | 4 ++++ Server/Scripts/Backup/CloudBackup.sh | 15 +++++++++++---- Server/Scripts/Backup/ExternalDataBackup.sh | 2 +- Server/Scripts/Backup/ServerDataBackup.sh | 2 +- Server/diycron | 12 ++++++------ 6 files changed, 30 insertions(+), 12 deletions(-) create mode 100755 Server/.Repo.Update.sh diff --git a/Server/.Repo.Update.sh b/Server/.Repo.Update.sh new file mode 100755 index 0000000..cae3a33 --- /dev/null +++ b/Server/.Repo.Update.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +cd "$( dirname "$( realpath "$0" )" )" + +cp -v /etc/diycron ./diycron +cp -v /Server/Scripts/Backup/*.sh ./Scripts/Backup/ +cp -v /Server/Scripts/Backup/*.cfg ./Scripts/Backup/ diff --git a/Server/Scripts/Backup/BackupGlobals.cfg b/Server/Scripts/Backup/BackupGlobals.cfg index d4c2e65..1a5733a 100644 --- a/Server/Scripts/Backup/BackupGlobals.cfg +++ b/Server/Scripts/Backup/BackupGlobals.cfg @@ -21,3 +21,7 @@ ccencryptNow() { BaseKey="$2" ccrypt -e -f -K"$(Hash2 "${BaseKey}" "${RunDate}")" "${File}" } + +WriteLastLog() { + echo "$0: $(date)" > "${BackupsBase}/Last.log" +} diff --git a/Server/Scripts/Backup/CloudBackup.sh b/Server/Scripts/Backup/CloudBackup.sh index 59057fc..f557d25 100755 --- a/Server/Scripts/Backup/CloudBackup.sh +++ b/Server/Scripts/Backup/CloudBackup.sh @@ -4,9 +4,14 @@ . "$(dirname "$(realpath "$0")")/BackupGlobals.cfg" GitPush() { - git add . - git commit -m "Auto-Backup $(date) (${RunDate})" - git push + Msg="Auto-Backup $(date) (${RunDate})" + git add . && git commit -m "${Msg}" && git push +} + +GitPullPushPath() { + BackPath="$(pwd)" + cd "$1" && git pull && GitPush + cd "${BackPath}" } cd ./Server-Backup-Limited @@ -16,6 +21,8 @@ Item="FreshRSS-data" && cp "../${Item}/Latest.tar.xz" "./${Item}.tar.xz" && ccen GitPush cd .. +#GitPullPushPath "./Personal-Game-Saves" + #CloudDir="/home/octo/Cloud" #cd "$CloudDir" @@ -51,4 +58,4 @@ cd .. #done #GitPush -date > "${BackupsBase}/Last.log" +WriteLastLog diff --git a/Server/Scripts/Backup/ExternalDataBackup.sh b/Server/Scripts/Backup/ExternalDataBackup.sh index ae6e710..94b8de5 100755 --- a/Server/Scripts/Backup/ExternalDataBackup.sh +++ b/Server/Scripts/Backup/ExternalDataBackup.sh @@ -11,4 +11,4 @@ curl \ -H "${Invidious_Backup_Cookie}" \ | 7z a -mmt1 -mx9 "./${Name}/${RunDate}.7z" -si && cp "./${Name}/${RunDate}.7z" "./${Name}/Latest.7z" -date > "${BackupsBase}/Last.log" +WriteLastLog diff --git a/Server/Scripts/Backup/ServerDataBackup.sh b/Server/Scripts/Backup/ServerDataBackup.sh index c144194..52115e1 100755 --- a/Server/Scripts/Backup/ServerDataBackup.sh +++ b/Server/Scripts/Backup/ServerDataBackup.sh @@ -41,4 +41,4 @@ SimpleBackup "FreshRSS-data" # cd .. #done -date > "${BackupsBase}/Last.log" +WriteLastLog diff --git a/Server/diycron b/Server/diycron index 80d8e45..0fd8443 100755 --- a/Server/diycron +++ b/Server/diycron @@ -31,16 +31,16 @@ do # 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 + 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 # 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 + # System reboot every X days at 4:30 AM + #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 + 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