src.nth.io/

summaryrefslogtreecommitdiff
path: root/roles/pleroma-otp/files
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2020-01-20 13:18:18 -0600
committerLuke Hoersten <[email protected]>2020-01-20 13:18:18 -0600
commit1ed732d2f7c8de86e5c290bd38aaa63761654ac5 (patch)
treea30c512eb7bdb156745c988366f921aedf2bc0ae /roles/pleroma-otp/files
parent9eb223531a017cca2c11a152ede197c8798b5684 (diff)
Added pleroma instance backup to s3.
Diffstat (limited to 'roles/pleroma-otp/files')
-rw-r--r--roles/pleroma-otp/files/pleroma-s3-backup.sh26
-rw-r--r--roles/pleroma-otp/files/[email protected]9
2 files changed, 35 insertions, 0 deletions
diff --git a/roles/pleroma-otp/files/pleroma-s3-backup.sh b/roles/pleroma-otp/files/pleroma-s3-backup.sh
new file mode 100644
index 0000000..7c1d6d3
--- /dev/null
+++ b/roles/pleroma-otp/files/pleroma-s3-backup.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+INSTANCE=$1
+DATE=`date --iso-8601`
+
+BUCKET="pleroma-${INSTANCE//_/-}-backup"
+BACKUP_DIR="/tmp/s3-backup/$BUCKET"
+BACKUP_TAR="/tmp/s3-backup/$BUCKET-$DATE.tgz"
+
+DB_NAME="pleroma_$INSTANCE"
+CONFIG="/etc/pleroma/$INSTANCE.config.exs"
+
+UPLOADS_DIR=`grep uploads $CONFIG | cut -d '"' -f 2`
+STATIC_DIR=`grep static $CONFIG | cut -d '"' -f 2`
+
+mkdir -m 775 -p "$BACKUP_DIR/"
+chown root:postgres "$BACKUP_DIR/"
+
+su postgres -c "pg_dump -d $DB_NAME --format=custom -f $BACKUP_DIR/$DB_NAME.pgdump"
+cp $CONFIG "$BACKUP_DIR/"
+cp -r $UPLOADS_DIR "$BACKUP_DIR/"
+cp -r $STATIC_DIR "$BACKUP_DIR/"
+
+tar -zc -f $BACKUP_TAR $BACKUP_DIR
+aws s3 mb "s3://$BUCKET/"
+aws s3 cp $BACKUP_TAR "s3://$BUCKET/"
diff --git a/roles/pleroma-otp/files/[email protected] b/roles/pleroma-otp/files/[email protected]
new file mode 100644
index 0000000..7459f02
--- /dev/null
+++ b/roles/pleroma-otp/files/[email protected]
@@ -0,0 +1,9 @@
+[Unit]
+Description=Pleroma s3 backup for instance "%I"
+
+[Service]
+Type=oneshot
+ExecStart=/usr/local/bin/pleroma-prepare-backup.sh %i
+
+[Install]
+WantedBy=aws-s3-backup.target