1234567891011121314151617181920212223242526272829303132333435 |
- #!/bin/bash
- # Modified from https://gist.github.com/ssddanbrown/3d5dbebc51ac6ca45837d8a030b07b65
- # 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"
- # 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"
|