|
@@ -0,0 +1,49 @@
|
|
|
+#!/bin/bash
|
|
|
+
|
|
|
+# Modified from https://gist.github.com/ssddanbrown/8507ba236508ce5e362f1a7dc3b233cf
|
|
|
+
|
|
|
+# Directory to store backups within
|
|
|
+# Should not end with a slash and not be stored within
|
|
|
+# the BookStack directory
|
|
|
+BACKUP_ROOT_DIR="$HOME"
|
|
|
+
|
|
|
+# Directory of the BookStack install
|
|
|
+# Should not end with a slash.
|
|
|
+BOOKSTACK_DIR="/var/www/bookstack"
|
|
|
+
|
|
|
+# Enter BookStack dir
|
|
|
+cd $BOOKSTACK_DIR || exit
|
|
|
+
|
|
|
+# Check update
|
|
|
+git fetch origin release -n
|
|
|
+[ -n "$(git diff @ @{u})" ] || { echo "Up-to-date" && exit; }
|
|
|
+
|
|
|
+# Get database options from BookStack .env file
|
|
|
+export $(cat "$BOOKSTACK_DIR/.env" | grep ^DB_ | xargs)
|
|
|
+
|
|
|
+# Create an export name and location
|
|
|
+DATE=$(date "+%Y-%m-%d_%H-%M-%S")
|
|
|
+BACKUP_NAME="bookstack_backup_$DATE"
|
|
|
+BACKUP_DIR="$BACKUP_ROOT_DIR/$BACKUP_NAME"
|
|
|
+mkdir -p "$BACKUP_DIR"
|
|
|
+
|
|
|
+# Use loaded .env variables to create DB dump
|
|
|
+mysqldump -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" > "$BACKUP_DIR/database.sql"
|
|
|
+
|
|
|
+# Create backup archive
|
|
|
+tar -czpPf - "$BACKUP_DIR/database.sql" "$BOOKSTACK_DIR/.env" "$BOOKSTACK_DIR/storage/uploads" "$BOOKSTACK_DIR/public/uploads" "$BOOKSTACK_DIR/themes" \
|
|
|
+ | gpg -e -r 0 > "$BACKUP_DIR.tar.gz.gpg"
|
|
|
+
|
|
|
+# Cleanup non-archive directory
|
|
|
+rm -r "$BACKUP_DIR"
|
|
|
+
|
|
|
+# Upload archive
|
|
|
+rclone copy "$BACKUP_DIR.tar.gz.gpg" od-1:/upload -vP
|
|
|
+rm "$BACKUP_DIR.tar.gz.gpg"
|
|
|
+
|
|
|
+# Run BookStack upgrade commands
|
|
|
+git pull origin release
|
|
|
+composer install --no-dev
|
|
|
+php artisan migrate
|
|
|
+php artisan cache:clear
|
|
|
+php artisan view:clear
|