Parcourir la source

Add BookStack related scripts and update update_librex.sh

poesty il y a 1 an
Parent
commit
ef71952e08
3 fichiers modifiés avec 58 ajouts et 21 suppressions
  1. 5 14
      backup/backup_bookstack.sh
  2. 49 0
      update/update_bookstack.sh
  3. 4 7
      update/update_librex.sh

+ 5 - 14
backup/backup_bookstack.sh

@@ -3,7 +3,7 @@
 # Modified from https://gist.github.com/ssddanbrown/3d5dbebc51ac6ca45837d8a030b07b65
 
 # Directory to store backups within
-# Should not end with a slash and not be stored within 
+# Should not end with a slash and not be stored within
 # the BookStack directory
 BACKUP_ROOT_DIR="$HOME"
 
@@ -20,21 +20,12 @@ BACKUP_NAME="bookstack_backup_$DATE"
 BACKUP_DIR="$BACKUP_ROOT_DIR/$BACKUP_NAME"
 mkdir -p "$BACKUP_DIR"
 
-# Dump database to backup dir using the values
-# we got from the BookStack .env file.
-mysqldump --single-transaction \
- --no-tablespaces \
- -u "$DB_USERNAME" \
- -p"$DB_PASSWORD" \
- "$DB_DATABASE" > "$BACKUP_DIR/database.sql"
-
-# Copy BookStack files into backup dir
-cp "$BOOKSTACK_DIR/.env" "$BACKUP_DIR/.env"
-cp -a "$BOOKSTACK_DIR/storage/uploads" "$BACKUP_DIR/storage-uploads"
-cp -a "$BOOKSTACK_DIR/public/uploads" "$BACKUP_DIR/public-uploads"
+# 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 | gpg -e -r 0 > "$BACKUP_DIR.tar.gz.gpg"
+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"

+ 49 - 0
update/update_bookstack.sh

@@ -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

+ 4 - 7
update/update_librex.sh

@@ -1,9 +1,6 @@
 #!/bin/bash
 cd /root/librex
-git fetch
-if [ -n "$(git diff @ @{u})" ]; then
-  git pull
-  lftp -c "set sftp:auto-confirm yes; open sftp://[REDACTED]; mirror -Rev ./ [REMOTE]/ --only-newer --parallel=10 -X .htaccess -X config.php -X opensearch.xml -X robots.txt"
-else
-  echo "Up-to-date"
-fi
+git fetch origin main -n
+[ -n "$(git diff @ @{u})" ] || { echo "Up-to-date" && exit; }
+git pull
+lftp -c "set sftp:auto-confirm yes; open sftp://[REDACTED]; mirror -Rev ./ [REMOTE]/ --only-newer --parallel=10 -X .htaccess -X config.php -X opensearch.xml -X robots.txt"