New server

This commit is contained in:
2023-08-29 17:40:07 +02:00
parent 57e77ccf8c
commit a7ed28ff02
12 changed files with 61 additions and 45 deletions

View File

@ -0,0 +1,35 @@
#!/bin/sh
BackupsBase=/Main/Backup
#BackupsBase="/media/Disk/Backup"
# ScriptDir="$( dirname "$( realpath "$0" )" )"
# cd "$ScriptDir"
RunDate="$(date +%F)" # Current date in YYYY-MM-DD format
cd "${BackupsBase}"
. ./.BackupSecrects.sec
# Generate a good key for encrypting files, based on a primary secret key and a secondary string
# NOTE to self: Use this same function to get decryption key, plugging the YYYY-MM-DD date of the Git commit as $2
Hash2() {
BaseKey="$1"
SecStr="$2"
echo "$(echo "${BaseKey}$(echo "${SecStr}" | sha512sum | base64 -w0)" | sha512sum | base64 -w0)"
}
ccencryptNow() {
File="$1"
BaseKey="$2"
ccrypt -e -f -K"$(Hash2 "${BaseKey}" "${RunDate}")" "${File}"
}
WriteLastLog() {
echo "$0: $(date)" > "${BackupsBase}/Last.log"
}
EchoExec() {
echo "$@"
$@
}

View File

@ -0,0 +1,121 @@
#!/bin/sh
# Upload a backup of the Local Cloud and of local services backups to other clouds
set -e
. "$(dirname "$(realpath "$0")")/BackupGlobals.cfg"
GitPush() {
Msg="Auto-Backup $(date) (${RunDate})"
git add . && git commit -m "${Msg}" && git push
}
GitPullPushPath() {
BackPath="$(pwd)"
cd "$1" && git pull && GitPush
cd "${BackPath}"
}
BackPathCrypt() {
Folder="$1"
Key="$2"
Ext="$([ -z "$3" ] && echo ".tar.xz" || echo "$3")"
cp -v "../${Folder}/Latest${Ext}" "./${Folder}${Ext}" && \
ccencryptNow "./${Folder}${Ext}" "${Key}"
}
ServerBackupLimited(){
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
EchoExec cd ..
}
ArticlesBackupPrivate(){
EchoExec cd ./Articles-Backup-Private
EchoExec rm -rf ./shiori-data
EchoExec cp -rp "../shiori-data/Latest.d" "./shiori-data"
GitPush
EchoExec cd ..
}
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
for File in \
./Db.sql.tar.xz \
./SpaccBBS/config.php \
./SpaccBBS/arrowchat/includes/config.php \
; do ccencryptNow "$File" "$BackupKey_Git_SpaccBBS"
done
GitPush
EchoExec cd ..
}
DoSpaccCraftBackup(){
McServer="SpaccCraft"
McEdition="Beta-1.7.3"
McGit="spacccraft-b1.7.3-backup4"
DestPath="${BackupsBase}/${McGit}"
#DestPath="${BackupsBase}/${McServer}/${McGit}"
if [ -d "${DestPath}" ]
then
#cd "/Server/${McServer}"
cd "${BackupsBase}/${McServer}"
rm -rf "${DestPath}/${McEdition}"
cp ./*.sh "${DestPath}/"
cp -r "./${McEdition}/Latest.d" "${DestPath}/${McEdition}"
GitPullPushPath "${DestPath}"
fi
}
ServerBackupLimited
ArticlesBackupPrivate
DoSpaccBbsBackup
DoSpaccCraftBackup
#GitPullPushPath "/Cloud/Repos/Personal-Game-Saves"
#GitPullPushPath "/media/Disk/Configs"
#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
WriteLastLog

View File

@ -0,0 +1,18 @@
#!/bin/sh
# Make local backups of our data from various third-party services
set -e
. "$(dirname "$(realpath "$0")")/BackupGlobals.cfg"
# Invidious personal JSON dump
InvidiousPersonalJsonDump(){
Name="Invidious-User"
mkdir -vp "./${Name}"
curl \
"${Invidious_Backup_URL}/subscription_manager?action_takeout=1&format=json" \
-H "${Invidious_Backup_Cookie}" \
| 7z a -mmt1 -mx9 "./${Name}/${RunDate}.7z" -si && cp -v "./${Name}/${RunDate}.7z" "./${Name}/Latest.7z"
}
#InvidiousPersonalJsonDump
WriteLastLog

View File

@ -0,0 +1,73 @@
#!/bin/sh
# Make local backups of the data from the hosted services
set -e
. "$(dirname "$(realpath "$0")")/BackupGlobals.cfg"
SimpleCompress(){
EchoExec tar cJSf "$1.tar.xz" "$2"
}
SimpleBackup(){
# $1: Folder
# $2: Optional prefix relative to path in /Server
mkdir -vp "./$1"
#tar cvJSf "./$1/${RunDate}.tar.xz" "/Server/$2/$1" && \
#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 "/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 n8n-data
DoBackupShiori
DoBackupSpaccBBS
# 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
WriteLastLog

View File

@ -0,0 +1,7 @@
#!/bin/sh
cd "$( dirname "$( realpath "$0" )" )"
sh -c 'while true; do echo "nameserver 127.0.0.1" > /etc/resolv.conf; sleep 30; done' &
sh ./MountRoots.sh &
while true; do sleep 30; done

View File

@ -0,0 +1,9 @@
#!/bin/sh
systemctl stop nginx
#cd /etc/letsencrypt/live/
#for Domain in *.octt.eu.org
#do
# certbot certonly --standalone -d $Domain
#done
certbot renew
systemctl start nginx

View File

@ -0,0 +1,14 @@
#!/bin/sh
cd /Transfers/aria2
# Backup
7z a -mx9 -mmt1 "./Service.$(date "+%Y-%m-%d.%H:%M:%S").bak.7z" ./Service
while true
do
# Get global trackers updated today
Trackers="$(for i in $(curl https://ngosang.github.io/trackerslist/trackers_best.txt; curl https://newtrackon.com/api/stable); do echo "$i,"; done)"
[ -n "$Trackers" ] && Trackers="--bt-tracker=$(echo $(echo "$Trackers") | sed 's/ //g')"
aria2c --conf-path=./Conf/Server.conf --daemon=false $Trackers
done

View File

@ -0,0 +1,104 @@
# Promemoria, link per prendere spunto:
# * https://gist.github.com/qzm/a54559726896d5e6bf21adf2363ad334
# * https://libreddit.kavin.rocks/r/seedboxes/comments/fz2od8/unlimited_seeding_with_aria2/
# ** https://pastebin.com/Yyqubrci
# * https://gist.github.com/ifyour/2be0055adbaea83881aacaab905afd43
# Tip: load this file with: --conf-path=${FILE}
# Note: ensure files /Transfers/aria2/Service/{Session.dat,Cookies.txt} exist before starting, otherwise create as empty
# [ Misc ]
# Start as blocking for use within a systemd service
daemon=false
# Moderate logging to file
log-level=notice
log=/Transfers/aria2/Service/Log.log
# Remote control
enable-rpc=true
rpc-listen-all=true
rpc-listen-port=6800
rpc-allow-origin-all=true
rpc-secret=octt.pi
# Session data persistance
save-session=/Transfers/aria2/Service/Session.dat
input-file=/Transfers/aria2/Service/Session.dat
save-cookies=/Transfers/aria2/Service/Cookies.txt
load-cookies=/Transfers/aria2/Service/Cookies.txt
# Directory for storing downloads
dir=/Transfers/Storage
# Keep completed downloads in session (for seeding + stats)
force-save=true
# Set allow overwrite othewise sometimes torrents will stall
allow-overwrite=true
# Cache storage
dht-file-path=/Transfers/aria2/Service/DHT.dat
# RAM Cache for reducing disk I/O - 2x default
# Note: if too high, some could end up in swap, and decrease performance
disk-cache=32MB
# Mapping files in memory consumes high ram
# Note: can have issues on 32-bit systems
enable-mmap=false
# [ Connections ]
# As today no IPv6 on my WAN, so let's avoid overhead
disable-ipv6=true
# - 2x default
max-connection-per-server=4
# Max connections per file - 2x default
split=15
# Don't use multiple peers when file smaller than:
min-split-size=2M
# [ BitTorrent ]
# Store metadata to .torrent files and always load it
bt-save-metadata=true
bt-load-saved-metadata=true
# Don't account seeding torrents in global downloads limit
bt-detach-seed-only=true
# Ports or ranges of - More ports avoids too much saturation (?)
listen-port=6881-6883
dht-listen-port=6881-6883
# Peer discovery on the global Internet
enable-dht=true
# LAN peer discovery
# Note: it can cause LAN privacy issues, and with many torrents it could flood the LAN
bt-enable-lpd=true
bt-lpd-interface=wlan0
# More efficient transmission
enable-peer-exchange=true
# Max peers per torrent
bt-max-peers=100
# Seed forever
seed-ratio=0.0
# [ --- ]