Added Bookstack backup script.

master
parent 6bafc5e29c
commit ead9f85a10

@ -5,6 +5,9 @@
**aperture** <sub>and funperture</sub> **aperture** <sub>and funperture</sub>
A simple little script that echos one of two things. Either the aperture logo, or how the aperture logo got into the script. I like it. A simple little script that echos one of two things. Either the aperture logo, or how the aperture logo got into the script. I like it.
**backupBookstack.sh**
A script to back up a Bookstack instance (https://bookstackapp.com). I run it weekly. It works well enough for me to post it here so...
**backupProgramFiles.sh** **backupProgramFiles.sh**
This is a script that I created to zip up my Program Files folders on my C: drive as those are permanently excluded by the backup software I use. I could probably dive in and pick specific applications that I know store their configutaions in the Program Files folders but for now I just do the whole thing. This script also clears out backups older than 2 weeks (I run it weekly) and emails a summary to the provided address through the specified mail relay server. Be sure to edit smtp-creds.sh to include your information. This is a script that I created to zip up my Program Files folders on my C: drive as those are permanently excluded by the backup software I use. I could probably dive in and pick specific applications that I know store their configutaions in the Program Files folders but for now I just do the whole thing. This script also clears out backups older than 2 weeks (I run it weekly) and emails a summary to the provided address through the specified mail relay server. Be sure to edit smtp-creds.sh to include your information.

@ -0,0 +1,113 @@
#!/bin/bash
if [ $# -lt 3 ] && [ $# -gt 0 ]; then
cat << EOF
Incorrect number of arguments provided. Please either provide all
of the below arguments or provide none to use the default values
set in the script.
1: The domain (or name of your folder in /var/www)
2: The name of the application (to be used in naming the files)
3: The name of the database to back up
e.g. backupBookstack.sh docs.example.com docstack documentdb
^ (1) ^ (2) ^ (3)
EOF
exit 1
fi
if [[ `id -u` -ne 0 ]]; then
echo "This script must be run as root..."
exit 1
fi
domain="bookstack.dismyserver.net" # The name of the directory in /var/www
application="" # Only populate if this not the default bookstack instance
appdatabase="bookstack" # seems important to get right
sqlbackupuser="backupuser" # The user that has permission to dump DBs
sqlbackupuserpassword="hunter2" # Said user's password
termuser='rooot' # The user that you want to access the backup files with
backgroup='backupboi' # The group that can read the backup files
[ -z $application ] || application="${application}-"
[ -z $1 ] || domain=$1
[ -z $2 ] || application=$2
[ -z $3 ] || appdatabase=$3
isodate=`date +%Y-%m-%d_%H-%M-%S%z`
backupdir="/tmp/${application}bookstack-backup-${isodate}"
backupenddir="/backups/${application}bookstack"
mkdir -p $backupdir/public
mkdir -p $backupdir/storage
phpver=`php -v`
apachever=`apache2 -v`
apachemod=`apache2ctl -M 2>/dev/null`
serverver=`grep -h DISTRIB_DESCRIPTION /etc/*release | cut -d= -f2 | tr -d \"`
sqlver=`mysql --version`
cp -r /var/www/${domain}/public/uploads $backupdir/public/
cp -r /var/www/${domain}/storage/uploads $backupdir/storage/
cp /var/www/${domain}/.env* $backupdir/
cat > ${backupdir}/restore-notes.txt << EOF
Backup for ${isodate}
Backed up the following directories:
- /var/www/${domain}/public/uploads
- /var/www/${domain}/storage/uploads
- /var/www/${domain}/.env*
Backed up the following database:
- ${appdatabase}
7zip does not save file permissions or users/groups.
Be sure to change these manually if a restore is
performed.
https://www.bookstackapp.com/docs/admin/backup-restore/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The Boring Stuff
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Server Version
${serverver}
PHP Version
${phpver}
SQL Version
${sqlver}
Apache Version
${apachever}
Enabled Apache Modules
static = compiled into Apache
shared = dynamically loaded
${apachemod}
EOF
# https://bencane.com/2011/12/12/creating-a-read-only-backup-user-for-mysqldump/
mysqldump -u${sqlbackupuser} -p${sqlbackupuserpassword} ${appdatabase} > $backupdir/${application}bookstack-$isodate.sql
mkdir -p $backupenddir
7z a $backupenddir/${application}bookstack_$isodate.7z $backupdir/* >/dev/null
chown $termuser:$backgroup $backupenddir/${application}bookstack_$isodate.7z
chmod 640 $backupenddir/${application}bookstack_$isodate.7z
rm -rf $backupdir
Loading…
Cancel
Save