From b15ccc95b80e379d5a3093e951fb15c5334dad11 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Wed, 8 May 2024 14:07:35 +0500 Subject: [PATCH] Add backup script for public container --- bash_scripts/backup_public | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 bash_scripts/backup_public diff --git a/bash_scripts/backup_public b/bash_scripts/backup_public new file mode 100755 index 0000000..0ffad01 --- /dev/null +++ b/bash_scripts/backup_public @@ -0,0 +1,25 @@ +#!/usr/bin/sh + +BACKUP_ROOT="Backup $(date -Ihours)" +mkdir "$BACKUP_ROOT" + +# Lemmy +LEMMY_ROOT="$BACKUP_ROOT/Lemmy" +mkdir "$LEMMY_ROOT" +cp /opt/lemmy/lemmy-server/lemmy.hjson "$LEMMY_ROOT" + +# Forgejo +FORGEJO_ROOT="$BACKUP_ROOT/Forgejo" +mkdir "$FORGEJO_ROOT" +su forgejo -c "forgejo dump -f /tmp/forgejo.tar --type tar; tar -f /tmp/forgejo.tar --delete forgejo-db.sql" +cp /tmp/forgejo.tar "$FORGEJO_ROOT" + +# Postgres +POSTGRES_ROOT="$BACKUP_ROOT/Postgres" +mkdir "$POSTGRES_ROOT" +pg_dumpall -c -U postgres -f "$POSTGRES_ROOT/db.sql" + +# Compress and send +tar -cavf "./$BACKUP_ROOT.tar.zst" "./$BACKUP_ROOT" && rm -r "$BACKUP_ROOT" +scp "./$BACKUP_ROOT.tar.zst" public@10.44.82.1:~/ +rm "./$BACKUP_ROOT.tar.zst"