pleroma-otp/files/pleroma-s3-backup.sh
changeset 93 976670b2ca63
parent 88 63efc98132f7
equal deleted inserted replaced
92:d4924111ce28 93:976670b2ca63
       
     1 #!/bin/bash
       
     2 
       
     3 INSTANCE=$1
       
     4 DATE=`date --iso-8601`
       
     5 
       
     6 BUCKET="pleroma-${INSTANCE//_/-}-backup"
       
     7 BACKUP_DIR="/tmp/s3-backup/$BUCKET"
       
     8 BACKUP_TAR="/tmp/s3-backup/$BUCKET-$DATE.tgz"
       
     9 
       
    10 DB_NAME="pleroma_$INSTANCE"
       
    11 CONFIG="/etc/pleroma/$INSTANCE.config.exs"
       
    12 
       
    13 UPLOADS_DIR=`grep uploads $CONFIG | cut -d '"' -f 2`
       
    14 STATIC_DIR=`grep static $CONFIG | cut -d '"' -f 2`
       
    15 
       
    16 mkdir -m 775 -p "$BACKUP_DIR/"
       
    17 chown root:postgres "$BACKUP_DIR/"
       
    18 
       
    19 su postgres -c "pg_dump -d $DB_NAME --format=custom -f $BACKUP_DIR/$DB_NAME.pgdump"
       
    20 cp $CONFIG "$BACKUP_DIR/"
       
    21 cp -r $UPLOADS_DIR "$BACKUP_DIR/"
       
    22 cp -r $STATIC_DIR "$BACKUP_DIR/"
       
    23 
       
    24 tar -zc -f $BACKUP_TAR $BACKUP_DIR
       
    25 aws s3 mb "s3://$BUCKET/"
       
    26 aws s3 cp $BACKUP_TAR "s3://$BUCKET/"