Browse Source

Add backup_bookstack.sh and update Akkoma related scripts

poesty 1 year ago
parent
commit
f73c3131e6
3 changed files with 75 additions and 16 deletions
  1. 14 8
      backup/backup_akkoma.sh
  2. 44 0
      backup/backup_bookstack.sh
  3. 17 8
      update/update_akkoma.sh

+ 14 - 8
backup/backup_akkoma.sh

@@ -1,18 +1,20 @@
 #!/bin/bash
 
 # set vars
+BACKUP_ROOT_PATH=/tmp
+DATE=$(date +%Y%m%d-%H%M%S)
+BACKUP_NAME=akbk-$DATE
+BACKUP_PATH=$BACKUP_ROOT_PATH/$BACKUP_NAME
+mkdir -p $BACKUP_PATH
+chmod a+w $BACKUP_PATH
+
 AKKOMA_DB=pleroma
 AKKOMA_USER=pleroma
 AKKOMA_SERVICE=pleroma
 AKKOMA_PATH=/opt/pleroma
 AKKOMA_STATIC_PATH=/var/lib/pleroma
 AKKOMA_CONFIG_PATH=/etc/pleroma/config.exs
-AKKOMA_DBCONFIG_PATH=/tmp/config_db.exs
-BACKUP_PATH=/home/plbk
-
-# clean up
-rm $BACKUP_PATH/*
-rm $AKKOMA_DBCONFIG_PATH
+AKKOMA_DBCONFIG_PATH=$BACKUP_PATH/config_db.exs
 
 # export config in database
 cd $AKKOMA_PATH
@@ -24,10 +26,14 @@ systemctl stop $AKKOMA_SERVICE
 
 # backup database/config.exs/static files
 sudo -Hu postgres pg_dump -d $AKKOMA_DB  --format=custom -f $BACKUP_PATH/akkoma.pgdump
-tar -czpPf - $AKKOMA_STATIC_PATH $AKKOMA_CONFIG_PATH $BACKUP_PATH/akkoma.pgdump $AKKOMA_DBCONFIG_PATH | gpg -e -r 0 > $BACKUP_PATH/akbk+$(date +%Y%m%d-%H%M%S).tar.gz.gpg
+tar -czpPf - $AKKOMA_STATIC_PATH $AKKOMA_CONFIG_PATH $BACKUP_PATH | gpg -e -r 0 > $BACKUP_PATH.tar.gz.gpg
+rm -r $BACKUP_PATH
 
 # start akkoma
 systemctl start $AKKOMA_SERVICE
 
 # upload archive
-rclone copy /home/plbk/akbk+*.tar.gz.gpg od-1:/upload -vP
+rclone copy $BACKUP_PATH.tar.gz.gpg od-1:/upload -vP
+
+# clean up
+rm $BACKUP_PATH.tar.gz.gpg

+ 44 - 0
backup/backup_bookstack.sh

@@ -0,0 +1,44 @@
+#!/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"
+
+# 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"
+
+# Create backup archive
+tar -czpPf - $BACKUP_DIR | 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"

+ 17 - 8
update/update_akkoma.sh

@@ -1,18 +1,20 @@
 #!/bin/bash
 
 # set vars
+BACKUP_ROOT_PATH=/tmp
+DATE=$(date +%Y%m%d-%H%M%S)
+BACKUP_NAME=akbk-$DATE
+BACKUP_PATH=$BACKUP_ROOT_PATH/$BACKUP_NAME
+mkdir -p $BACKUP_PATH
+chmod a+w $BACKUP_PATH
+
 AKKOMA_DB=pleroma
 AKKOMA_USER=pleroma
 AKKOMA_SERVICE=pleroma
 AKKOMA_PATH=/opt/pleroma
 AKKOMA_STATIC_PATH=/var/lib/pleroma
 AKKOMA_CONFIG_PATH=/etc/pleroma/config.exs
-AKKOMA_DBCONFIG_PATH=/tmp/config_db.exs
-BACKUP_PATH=/home/plbk
-
-# clean up
-rm $BACKUP_PATH/*
-rm $AKKOMA_DBCONFIG_PATH
+AKKOMA_DBCONFIG_PATH=$BACKUP_PATH/config_db.exs
 
 # export config in database
 cd $AKKOMA_PATH
@@ -24,7 +26,8 @@ systemctl stop $AKKOMA_SERVICE
 
 # backup database/config.exs/static files
 sudo -Hu postgres pg_dump -d $AKKOMA_DB  --format=custom -f $BACKUP_PATH/akkoma.pgdump
-tar -czpPf - $AKKOMA_STATIC_PATH $AKKOMA_CONFIG_PATH $BACKUP_PATH/akkoma.pgdump $AKKOMA_DBCONFIG_PATH | gpg -e -r 0 > $BACKUP_PATH/akbk+$(date +%Y%m%d-%H%M%S).tar.gz.gpg
+tar -czpPf - $AKKOMA_STATIC_PATH $AKKOMA_CONFIG_PATH $BACKUP_PATH | gpg -e -r 0 > $BACKUP_PATH.tar.gz.gpg
+rm -r $BACKUP_PATH
 
 # update backend
 su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl update --branch stable" && su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl migrate"
@@ -32,8 +35,14 @@ su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl update --branch stable" && su $
 # start akkoma
 systemctl start $AKKOMA_SERVICE
 
+# wait for startup
+sleep 4s
+
 # update frontend
 su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl frontend install pleroma-fe --ref stable" && su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl frontend install admin-fe --ref stable"
 
 # upload archive
-rclone copy /home/plbk/akbk+*.tar.gz.gpg od-1:/upload -vP
+rclone copy $BACKUP_PATH.tar.gz.gpg od-1:/upload -vP
+
+# clean up
+rm $BACKUP_PATH.tar.gz.gpg