author | Luke Hoersten <luke@hoersten.org> |
Fri, 09 Sep 2022 11:56:30 -0500 | |
changeset 190 | 59bef6fbab49 |
parent 157 | 5e5c9e605142 |
permissions | -rw-r--r-- |
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 |
|
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
5 |
BUCKET="pleroma-${INSTANCE//_/-}-backup" |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
6 |
BACKUP_DIR="/tmp/s3-backup/$BUCKET" |
157
5e5c9e605142
Add aws s3 versioning and lifecycles to backup.
Luke Hoersten <luke@hoersten.org>
parents:
109
diff
changeset
|
7 |
BACKUP_TAR="/tmp/s3-backup/$BUCKET.tgz" |
88
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
8 |
|
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
9 |
DB_NAME="pleroma_$INSTANCE" |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
10 |
CONFIG="/etc/pleroma/$INSTANCE.config.exs" |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
11 |
|
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
12 |
UPLOADS_DIR=`grep uploads $CONFIG | cut -d '"' -f 2` |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
13 |
STATIC_DIR=`grep static $CONFIG | cut -d '"' -f 2` |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
14 |
|
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
15 |
mkdir -m 775 -p "$BACKUP_DIR/" |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
16 |
chown root:postgres "$BACKUP_DIR/" |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
17 |
|
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
18 |
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
|
19 |
cp $CONFIG "$BACKUP_DIR/" |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
20 |
cp -r $UPLOADS_DIR "$BACKUP_DIR/" |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
21 |
cp -r $STATIC_DIR "$BACKUP_DIR/" |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
22 |
|
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
23 |
tar -zc -f $BACKUP_TAR $BACKUP_DIR |
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
24 |
aws s3 mb "s3://$BUCKET/" |
157
5e5c9e605142
Add aws s3 versioning and lifecycles to backup.
Luke Hoersten <luke@hoersten.org>
parents:
109
diff
changeset
|
25 |
aws s3api put-bucket-versioning --bucket "$BUCKET" --versioning-configuration Status=Enabled |
5e5c9e605142
Add aws s3 versioning and lifecycles to backup.
Luke Hoersten <luke@hoersten.org>
parents:
109
diff
changeset
|
26 |
aws s3api put-bucket-lifecycle-configuration --bucket "$BUCKET" --lifecycle-configuration "file:///usr/local/share/pleroma-s3-backup-lifecycle.json" |
88
63efc98132f7
Added pleroma instance backup to s3.
Luke Hoersten <luke@hoersten.org>
parents:
diff
changeset
|
27 |
aws s3 cp $BACKUP_TAR "s3://$BUCKET/" |
109
646e4b395cc8
Added pleroma backup cleanup and mediaproxy.
Luke Hoersten <luke@hoersten.org>
parents:
103
diff
changeset
|
28 |
|
646e4b395cc8
Added pleroma backup cleanup and mediaproxy.
Luke Hoersten <luke@hoersten.org>
parents:
103
diff
changeset
|
29 |
rm $BACKUP_TAR |
646e4b395cc8
Added pleroma backup cleanup and mediaproxy.
Luke Hoersten <luke@hoersten.org>
parents:
103
diff
changeset
|
30 |
rm -r $BACKUP_DIR |