From 3bc0ded5a0f366674136d765cc05c9930637042e Mon Sep 17 00:00:00 2001 From: Raine Date: Thu, 23 May 2024 20:21:18 +0200 Subject: [PATCH] init --- README.md | 1 + fix-repo.sh | 8 ++++++ install.sh | 15 ++++++++++ main/bin/update-backups.sh | 56 ++++++++++++++++++++++++++++++++++++++ main/install.sh | 8 ++++++ nodes/etc/rsyncd.conf | 8 ++++++ nodes/install.sh | 6 ++++ 7 files changed, 102 insertions(+) create mode 100644 README.md create mode 100755 fix-repo.sh create mode 100755 install.sh create mode 100755 main/bin/update-backups.sh create mode 100755 main/install.sh create mode 100644 nodes/etc/rsyncd.conf create mode 100755 nodes/install.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..b948cb5 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Strix' final backup solution \ No newline at end of file diff --git a/fix-repo.sh b/fix-repo.sh new file mode 100755 index 0000000..db27112 --- /dev/null +++ b/fix-repo.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +for f in $(find . -iname '*.sh' -type 'f'); do + if ! [ -x $f ]; then + echo "fixing $f..." + chmod +x $f + fi +done \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..4729389 --- /dev/null +++ b/install.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +[ "$(id -u)" = "0" ] || exit 1 +[ $# -lt 1 ] && exit 1 + +case $1 in + node) + cd nodes + sh install.sh + ;; + main) + cd main + sh install.sh + ;; +esac \ No newline at end of file diff --git a/main/bin/update-backups.sh b/main/bin/update-backups.sh new file mode 100755 index 0000000..fed148b --- /dev/null +++ b/main/bin/update-backups.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +set -o errexit +set -o nounset +set -o pipefail + +backup_root="/var/lib/sfbs/backups" + +for host in $(cat /var/lib/sfbs/hosts | grep -v '#'); do + dtime="$(date '+%Y-%m-%d_%H:%M:%S')" + latest_link="$backup_root/$host/latest" + backup_path="$backup_root/$host/$dtime" + + mkdir -p $backup_path + + echo "pulling $host's fs..." + + rsync -av --delete \ + sfbs@$host::sfbs/ \ + --link-dest "$latest_link" \ + --password-file="/var/lib/sfbs/rsync-password" \ + --include="/usr/local" \ + --exclude="/usr/*" \ + --exclude="/tmp/*" \ + --exclude="/sys/*" \ + --exclude="/dev/*" \ + --exclude="/proc/*" \ + --exclude="/run/*" \ + --exclude="/mnt/*" \ + --exclude="/media/*" \ + --exclude="/var/lib/sfbs/backups/*" \ + --exclude="/home/*/.rustup/*" \ + --exclude="/home/*/*Cache*/*" \ + --exclude="/home/*/*cache*/*" \ + --exclude="/home/*/.cache*/*" \ + --exclude="/home/*/.gradle/*" \ + --exclude="/home/*/.nvm/*" \ + --exclude="/home/*/Downloads/*" \ + --exclude="/home/*/Trash/*" \ + --exclude="/home/*/.config/chromium/*" \ + --exclude="/home/*/.local/*/pnpm/*" \ + --exclude="/home/*/.local/*/gnome-boxes/*" \ + --exclude="/home/*/JetBrains/Toolbox/apps/*" \ + --exclude="/home/*/code/*/dist/*" \ + --exclude="/home/*/code/*/venv/*" \ + --exclude="/home/*/code/*/target/*" \ + --exclude="/home/*/code/*/vendor/*" \ + --exclude="/home/*/code/*/output/*" \ + --exclude="/home/*/code/*/build/*" \ + --exclude="/home/*/code/*/node_modules/*" \ + "$backup_path" + + rm -rf "$latest_link" + ln -s "$backup_path" "$latest_link" + +done diff --git a/main/install.sh b/main/install.sh new file mode 100755 index 0000000..8fe311e --- /dev/null +++ b/main/install.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +[ -d "/var/lib/sfbs/backups" ] || mkdir -p /var/lib/sfbs/backups +[ -d "/opt/sfbs" ] || mkdir -p /opt/sfbs +cp -r ./bin/. /opt/sfbs/bin +[ -f "/var/lib/sfbs/hosts" ] || (echo "# Here you can include hosts for sfbs." > /var/lib/sfbs/hosts) +[ -f "/var/lib/sfbs/rsync-password" ] || touch /var/lib/sfbs/rsync-password +chmod 600 /var/lib/sfbs/rsync-password \ No newline at end of file diff --git a/nodes/etc/rsyncd.conf b/nodes/etc/rsyncd.conf new file mode 100644 index 0000000..b580afe --- /dev/null +++ b/nodes/etc/rsyncd.conf @@ -0,0 +1,8 @@ +[sfbs] +path = / +comment = "Full file-system share for sbfs" +read only = true +exclude = *.tar.old +refuse options = delete +auth users = @guset:deny, sfbs:ro +secrets file = /var/lib/sfbs/rsync-auth \ No newline at end of file diff --git a/nodes/install.sh b/nodes/install.sh new file mode 100755 index 0000000..4095d73 --- /dev/null +++ b/nodes/install.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +cp ./etc/rsyncd.conf /etc/rsyncd.conf +[ -d "/var/lib/sfbs" ] || mkdir -p /var/lib/sfbs +[ -f "/var/lib/sfbs/rsync-password" ] || openssl rand -hex 16 > /var/lib/sfbs/rsync-password +[ -f "/var/lib/sfbs/rsync-auth" ] || (echo "sfbs:$(cat /var/lib/sfbs/rsync-password)" > /var/lib/sfbs/rsync-auth) \ No newline at end of file