|
|
@ -1,19 +1,46 @@
|
|
|
|
#!/bin/bash
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
if [ $# -lt 3 ] && [ $# -gt 0 ]; then
|
|
|
|
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
|
|
|
|
|
|
|
|
# USER CONFIGURED VARIABLES #
|
|
|
|
|
|
|
|
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
domain="bookstack.dismyserver.net" # The name of the directory in /var/www
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
arg1=$1
|
|
|
|
|
|
|
|
[ $arg1 == "-h" ] && helpme=1;arg1=$2
|
|
|
|
|
|
|
|
[ -z $arg1 ] || domain=$arg1
|
|
|
|
|
|
|
|
application=''
|
|
|
|
|
|
|
|
if [ $domain != "bookstack.dismyserver.net" ]; then
|
|
|
|
|
|
|
|
if [[ $domain == *"."* ]] && [ -z $2 ]; then
|
|
|
|
|
|
|
|
application=`echo $domain | cut -d. -f2`
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
[ -z $2 ] && application=$domain || application=$2
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ $# -gt 2 ] || [ $helpme ]; then
|
|
|
|
|
|
|
|
|
|
|
|
cat << EOF
|
|
|
|
cat << EOF
|
|
|
|
|
|
|
|
|
|
|
|
Incorrect number of arguments provided. Please either provide all
|
|
|
|
No arguments will follow the default values provided at the top of the script.
|
|
|
|
of the below arguments or provide none to use the default values
|
|
|
|
|
|
|
|
set in the script.
|
|
|
|
Current defaults:
|
|
|
|
|
|
|
|
|
|
|
|
1: The domain (or name of your folder in /var/www)
|
|
|
|
domain: ${domain}
|
|
|
|
2: The name of the application (to be used in naming the files)
|
|
|
|
application: ${application}
|
|
|
|
3: The name of the database to back up
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e.g. backupBookstack.sh docs.example.com docstack documentdb
|
|
|
|
Usage:
|
|
|
|
^ (1) ^ (2) ^ (3)
|
|
|
|
|
|
|
|
|
|
|
|
backupBookstack.sh [domain/folder] [name]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- domain/folder is the directory in /var/www that your bookstack instance lives
|
|
|
|
|
|
|
|
- name is useful if your directory does not have any periods and you do not want to use the domain name as the application name.
|
|
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
exit 1
|
|
|
@ -21,24 +48,13 @@ fi
|
|
|
|
|
|
|
|
|
|
|
|
if [[ `id -u` -ne 0 ]]; then
|
|
|
|
if [[ `id -u` -ne 0 ]]; then
|
|
|
|
echo "This script must be run as root..."
|
|
|
|
echo "This script must be run as root..."
|
|
|
|
exit 1
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
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 $application ] || application="${application}-"
|
|
|
|
[ -z $1 ] || domain=$1
|
|
|
|
|
|
|
|
[ -z $2 ] || application=$2
|
|
|
|
|
|
|
|
[ -z $3 ] || appdatabase=$3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
appdatabase=`grep DB_DATABASE /var/www/${domain}/.env | cut -d= -f2`
|
|
|
|
|
|
|
|
[ -z $appdatabase ] && echo "Unable to determine database. Exiting.";exit 1
|
|
|
|
isodate=`date +%Y-%m-%d_%H-%M-%S%z`
|
|
|
|
isodate=`date +%Y-%m-%d_%H-%M-%S%z`
|
|
|
|
backupdir="/tmp/${application}bookstack-backup-${isodate}"
|
|
|
|
backupdir="/tmp/${application}bookstack-backup-${isodate}"
|
|
|
|
backupenddir="/backups/${application}bookstack"
|
|
|
|
backupenddir="/backups/${application}bookstack"
|
|
|
@ -106,6 +122,7 @@ EOF
|
|
|
|
mysqldump -u${sqlbackupuser} -p${sqlbackupuserpassword} ${appdatabase} > $backupdir/${application}bookstack-$isodate.sql
|
|
|
|
mysqldump -u${sqlbackupuser} -p${sqlbackupuserpassword} ${appdatabase} > $backupdir/${application}bookstack-$isodate.sql
|
|
|
|
|
|
|
|
|
|
|
|
mkdir -p $backupenddir
|
|
|
|
mkdir -p $backupenddir
|
|
|
|
|
|
|
|
chown -R $termuser:$backgroup $backupenddir
|
|
|
|
|
|
|
|
|
|
|
|
7z a $backupenddir/${application}bookstack_$isodate.7z $backupdir/* >/dev/null
|
|
|
|
7z a $backupenddir/${application}bookstack_$isodate.7z $backupdir/* >/dev/null
|
|
|
|
chown $termuser:$backgroup $backupenddir/${application}bookstack_$isodate.7z
|
|
|
|
chown $termuser:$backgroup $backupenddir/${application}bookstack_$isodate.7z
|
|
|
|