author | Luke Hoersten <luke@hoersten.org> |
Wed, 01 Jul 2020 13:09:31 -0500 | |
changeset 104 | 73eb2db468ec |
parent 103 | 78a072bbf3c1 |
child 109 | 646e4b395cc8 |
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 |
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/" |