Created
May 28, 2020 16:34
-
-
Save glnarayanan/f1c37413cb558f028b37b439c68693e1 to your computer and use it in GitHub Desktop.
Outline Wiki Backup Script for S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pushd () | |
{ | |
dirname=$1 | |
DIR_STACK="$dirname ${DIR_STACK:-$PWD' '}" | |
cd ${dirname:?"missing directory name."} | |
echo "$DIR_STACK" | |
} | |
# Amazon S3 bucket information | |
# | |
AWS_BUCKET_NAME="<CONFIGURE_YOUR_AWS_BUCKET_NAME>" | |
AWS_BUCKET_FOLDER="<CONFIGURE_THE_FOLDER_NAME_OR_PATH_WHERE_YOU_WANT_THE_BACKUP_FILES_TO_BE_STORED_IN_S3>" | |
# Local directory to store backups | |
BACKUP_PATH="<PATH_TO_BACKUP_DIRECTORY_IN_THE_INSTANCE>" | |
OUTLINE_PATH="<PATH_TO_OUTLINE_INSTALLATION_DIRECTORY_IN_THE_INSTANCE>" | |
# Timestamp format | |
TIMESTAMP=$(date +"%F_%T") | |
# Delete local backup files older than 30 days | |
find $BACKUP_PATH/ -name "*zip" -mtime +30 -exec rm {} \; | |
# Set default file permissions | |
umask 117 | |
# Backup the Postgres database | |
# The authentication method should be set to "trust" in the pg_hba.conf for local connections | |
pg_dump -U <DB_USERNAME> <DBNAME> > /tmp/outline-$TIMESTAMP.sql | |
# Create a zip archive of the .env file, Server config, and Postgres database | |
# OPTIONAL TO BACKUP .ENV AND SITE CONFIG | |
# cp $OUTLINE_PATH/.env /tmp | |
# cp /etc/nginx/sites-available/<SITE_CONF> /tmp #NGINX CONF - REPLACE WITH THE PATH TO YOUR APACHE VHOST FILE IF YOU ARE USING APACHE | |
pushd /tmp | |
zip -q $BACKUP_PATH/website-$TIMESTAMP.zip ./outline-$TIMESTAMP.sql | |
zip -q $BACKUP_PATH/website-$TIMESTAMP.zip ./.env | |
zip -q $BACKUP_PATH/website-$TIMESTAMP.zip ./<SITE_CONF> | |
rm -rf /tmp/outline-$TIMESTAMP.sql | |
rm -rf /tmp/.env | |
rm -rf /tmp/<SITE_CONF> | |
# Upload the latest backup to Amazon S3 | |
s3cmd put $BACKUP_PATH/website-$TIMESTAMP.zip s3://$AWS_BUCKET_NAME$AWS_BUCKET_FOLDER/$TIMESTAMP.zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment