update_bookstack.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # Modified from https://gist.github.com/ssddanbrown/8507ba236508ce5e362f1a7dc3b233cf
  3. # Directory to store backups within
  4. # Should not end with a slash and not be stored within
  5. # the BookStack directory
  6. BACKUP_ROOT_DIR="$HOME"
  7. # Directory of the BookStack install
  8. # Should not end with a slash.
  9. BOOKSTACK_DIR="/var/www/bookstack"
  10. # Enter BookStack dir
  11. cd $BOOKSTACK_DIR || exit
  12. # Check update
  13. git fetch origin release -n --quiet
  14. git diff --quiet HEAD FETCH_HEAD && echo "Up-to-date" && exit
  15. # Get database options from BookStack .env file
  16. export $(cat "$BOOKSTACK_DIR/.env" | grep ^DB_ | xargs)
  17. # Create an export name and location
  18. DATE=$(date "+%Y-%m-%d_%H-%M-%S")
  19. BACKUP_NAME="bookstack_backup_$DATE"
  20. BACKUP_DIR="$BACKUP_ROOT_DIR/$BACKUP_NAME"
  21. mkdir -p "$BACKUP_DIR"
  22. # Use loaded .env variables to create DB dump
  23. mysqldump -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" > "$BACKUP_DIR/database.sql"
  24. # Create backup archive
  25. tar -czpPf - "$BACKUP_DIR/database.sql" "$BOOKSTACK_DIR/.env" "$BOOKSTACK_DIR/storage/uploads" "$BOOKSTACK_DIR/public/uploads" "$BOOKSTACK_DIR/themes" \
  26. | gpg -e -r 0 > "$BACKUP_DIR.tar.gz.gpg"
  27. # Cleanup non-archive directory
  28. rm -r "$BACKUP_DIR"
  29. # Upload archive
  30. rclone copy "$BACKUP_DIR.tar.gz.gpg" od-1:/upload -vP
  31. rm "$BACKUP_DIR.tar.gz.gpg"
  32. # Run BookStack upgrade commands
  33. git pull origin release --quiet
  34. composer install --no-dev -n -q --no-progress
  35. php artisan migrate
  36. php artisan cache:clear
  37. php artisan view:clear