dendrite/aws-s3-backup/files/pleroma-s3-backup.sh
changeset 174 431c6d5e5dd4
parent 157 5e5c9e605142
equal deleted inserted replaced
173:82f2bcbc5aca 174:431c6d5e5dd4
       
     1 #!/bin/bash
       
     2 
       
     3 INSTANCE=$1
       
     4 
       
     5 BUCKET="pleroma-${INSTANCE//_/-}-backup"
       
     6 BACKUP_DIR="/tmp/s3-backup/$BUCKET"
       
     7 BACKUP_TAR="/tmp/s3-backup/$BUCKET.tgz"
       
     8 
       
     9 DB_NAME="pleroma_$INSTANCE"
       
    10 CONFIG="/etc/pleroma/$INSTANCE.config.exs"
       
    11 
       
    12 UPLOADS_DIR=`grep uploads $CONFIG | cut -d '"' -f 2`
       
    13 STATIC_DIR=`grep static $CONFIG | cut -d '"' -f 2`
       
    14 
       
    15 mkdir -m 775 -p "$BACKUP_DIR/"
       
    16 chown root:postgres "$BACKUP_DIR/"
       
    17 
       
    18 su postgres -c "pg_dump -d $DB_NAME --format=custom -f $BACKUP_DIR/$DB_NAME.pgdump"
       
    19 cp $CONFIG "$BACKUP_DIR/"
       
    20 cp -r $UPLOADS_DIR "$BACKUP_DIR/"
       
    21 cp -r $STATIC_DIR "$BACKUP_DIR/"
       
    22 
       
    23 tar -zc -f $BACKUP_TAR $BACKUP_DIR
       
    24 aws s3 mb "s3://$BUCKET/"
       
    25 aws s3api put-bucket-versioning --bucket "$BUCKET" --versioning-configuration Status=Enabled
       
    26 aws s3api put-bucket-lifecycle-configuration --bucket "$BUCKET" --lifecycle-configuration "file:///usr/local/share/pleroma-s3-backup-lifecycle.json"
       
    27 aws s3 cp $BACKUP_TAR "s3://$BUCKET/"
       
    28 
       
    29 rm $BACKUP_TAR
       
    30 rm -r $BACKUP_DIR