pleroma/aws-s3-backup/files/pleroma-s3-backup.sh
author Luke Hoersten <luke@hoersten.org>
Sun, 05 Jul 2020 11:28:44 -0500
changeset 119 a96a5eb96e32
parent 109 646e4b395cc8
child 157 5e5c9e605142
permissions -rw-r--r--
Added nginx config template.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
     1
#!/bin/bash
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
     2
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
     3
INSTANCE=$1
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
     4
DATE=`date --iso-8601`
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
     5
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
     6
BUCKET="pleroma-${INSTANCE//_/-}-backup"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
     7
BACKUP_DIR="/tmp/s3-backup/$BUCKET"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
     8
BACKUP_TAR="/tmp/s3-backup/$BUCKET-$DATE.tgz"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
     9
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    10
DB_NAME="pleroma_$INSTANCE"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    11
CONFIG="/etc/pleroma/$INSTANCE.config.exs"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    12
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    13
UPLOADS_DIR=`grep uploads $CONFIG | cut -d '"' -f 2`
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    14
STATIC_DIR=`grep static $CONFIG | cut -d '"' -f 2`
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    15
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    16
mkdir -m 775 -p "$BACKUP_DIR/"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    17
chown root:postgres "$BACKUP_DIR/"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    18
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    19
su postgres -c "pg_dump -d $DB_NAME --format=custom -f $BACKUP_DIR/$DB_NAME.pgdump"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    20
cp $CONFIG "$BACKUP_DIR/"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    21
cp -r $UPLOADS_DIR "$BACKUP_DIR/"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    22
cp -r $STATIC_DIR "$BACKUP_DIR/"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    23
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    24
tar -zc -f $BACKUP_TAR $BACKUP_DIR
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    25
aws s3 mb "s3://$BUCKET/"
63efc98132f7 Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff changeset
    26
aws s3 cp $BACKUP_TAR "s3://$BUCKET/"
109
646e4b395cc8 Added pleroma backup cleanup and mediaproxy.
Luke Hoersten <luke@hoersten.org>
parents: 103
diff changeset
    27
646e4b395cc8 Added pleroma backup cleanup and mediaproxy.
Luke Hoersten <luke@hoersten.org>
parents: 103
diff changeset
    28
rm $BACKUP_TAR
646e4b395cc8 Added pleroma backup cleanup and mediaproxy.
Luke Hoersten <luke@hoersten.org>
parents: 103
diff changeset
    29
rm -r $BACKUP_DIR