From d4bdc820d23ff3b6d490471bc266e8ab395ed738 Mon Sep 17 00:00:00 2001 From: dsc Date: Wed, 16 Mar 2022 17:38:11 +0200 Subject: [PATCH] Initial commit --- README.md | 8 ++++++++ backup.sh | 6 ++++++ main.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 README.md create mode 100644 backup.sh create mode 100644 main.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..7f7914f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +## stupidbackup + +Yes. + +```text +# weekly +0 0 * * 0 bash /path/to/main.sh +``` diff --git a/backup.sh b/backup.sh new file mode 100644 index 0000000..343cbbc --- /dev/null +++ b/backup.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +tar -zcvf "home.tar.gz" --exclude-vcs --exclude '.wow-shared-ringdb' --exclude '__pycache__' --exclude 'venv' --exclude '.cache' --exclude '.wownero' --exclude '/var/lib/postgresql' --exclude '/var/lib/redis' --exclude '/var/lib/snapd' --exclude '/var/lib/mysql' --exclude '*/build' --exclude '/var/log' --exclude '/var/lib/dpkg' --exclude '/var/lib/varnish' --exclude '/var/lib/apt' --exclude '/var/cache' --exclude '/var/log/journal' --exclude 'node_modules' --exclude '.bitmonero' --exclude 'lmdb' /home/ +tar -zcvf "etc.tar.gz" --exclude-vcs --exclude '.wow-shared-ringdb' --exclude '__pycache__' --exclude 'venv' --exclude '.cache' --exclude '.wownero' --exclude '/var/lib/postgresql' --exclude '/var/lib/redis' --exclude '/var/lib/snapd' --exclude '/var/lib/mysql' --exclude '*/build' --exclude '/var/log' --exclude '/var/lib/dpkg' --exclude '/var/lib/varnish' --exclude '/var/lib/apt' --exclude '/var/cache' --exclude '/var/log/journal' --exclude 'node_modules' --exclude '.bitmonero' --exclude 'lmdb' /etc/ +tar -zcvf "var.tar.gz" --exclude-vcs --exclude '.wow-shared-ringdb' --exclude '__pycache__' --exclude 'venv' --exclude '.cache' --exclude '.wownero' --exclude '/var/lib/postgresql' --exclude '/var/lib/redis' --exclude '/var/lib/snapd' --exclude '/var/lib/mysql' --exclude '*/build' --exclude '/var/log' --exclude '/var/lib/dpkg' --exclude '/var/lib/varnish' --exclude '/var/lib/apt' --exclude '/var/cache' --exclude '/var/log/journal' --exclude 'node_modules' --exclude '.bitmonero' --exclude 'lmdb' /var/ +su postgres -c 'pg_dumpall' | gzip > all.sql.gz diff --git a/main.sh b/main.sh new file mode 100644 index 0000000..abe77f2 --- /dev/null +++ b/main.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +lockfile="/tmp/stupidbackup.lock" +exec 9>"$lockfile" +if ! flock -n 9 +then printf 'Only one running instance is allowed.\n'; + exit 1 +fi + +destination="/mnt/bigstorage/" +dontcare="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR" +now=`date +"%Y-%m-%d"` +path_script="$(realpath "${BASH_SOURCE[-1]}")" +path_dir="$(dirname "$path_script")" + +for domain in "login.wownero.com" "wownero.com" "git.wownero.com"; do + host="root@$domain" + tmpd=`ssh $dontcare "$host" "mktemp -d -t wow-XXXXXXXXXX"` + + if [ -z "$tmpd" ] + then + echo "[$domain] failed to create tmp directory" + continue + fi + + echo "[$domain] created $tmpd" + + scp $dontcare -rP22 "$path_dir/backup.sh" "$host:$tmpd/backup.sh" + echo "[$domain] uploaded backup script" + + ssh $dontcare "$host" "cd $tmpd; bash $tmpd/backup.sh" + echo "[$domain] executed backup script" + + scp $dontcare -rP22 "$host:$tmpd" "$destination/$now-$domain" + echo "[$domain] downloaded backups" + + ssh $dontcare "$host" "rm -rf $tmpd" + echo "[$domain] finished" +done + +rm "$lockfile" + +# delete old files +find $destination -type f -mtime +40 -delete