2015-12-08 12:40:41 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# Backup to local storage - typically a USB drive
|
|
|
|
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
PROJECT_NAME='freedombone'
|
2015-12-08 13:29:01 +01:00
|
|
|
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
|
2015-12-11 17:06:28 +01:00
|
|
|
BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
|
2015-12-08 12:40:41 +01:00
|
|
|
|
|
|
|
export TEXTDOMAIN=${PROJECT_NAME}-backup-local
|
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
|
|
|
|
|
|
|
USB_DRIVE=/dev/sdb1
|
|
|
|
USB_MOUNT=/mnt/usb
|
|
|
|
|
2015-12-09 10:38:51 +01:00
|
|
|
# get default USB from config file
|
|
|
|
CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
|
|
|
|
if [ -f $CONFIG_FILE ]; then
|
|
|
|
if grep -q "USB_DRIVE=" $CONFIG_FILE; then
|
|
|
|
USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
ADMIN_USERNAME=
|
|
|
|
ADMIN_NAME=
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-23 00:08:15 +01:00
|
|
|
# The name of a currently suspended site
|
|
|
|
# Sites are suspended so that verification should work
|
|
|
|
SUSPENDED_SITE=
|
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
DATABASE_PASSWORD=''
|
|
|
|
if [ -f /root/dbpass ]; then
|
|
|
|
DATABASE_PASSWORD=$(cat /root/dbpass)
|
2015-12-08 12:40:41 +01:00
|
|
|
fi
|
|
|
|
|
2015-12-23 00:08:15 +01:00
|
|
|
function suspend_site {
|
|
|
|
# suspends a given website
|
|
|
|
SUSPENDED_SITE="$1"
|
|
|
|
nginx_dissite $SUSPENDED_SITE
|
|
|
|
service nginx reload
|
|
|
|
}
|
|
|
|
|
|
|
|
function restart_site {
|
|
|
|
# restarts a given website
|
|
|
|
if [ ! $SUSPENDED_SITE ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
nginx_ensite $SUSPENDED_SITE
|
|
|
|
service nginx reload
|
|
|
|
SUSPENDED_SITE=
|
|
|
|
}
|
2015-12-09 13:21:47 +01:00
|
|
|
|
|
|
|
function update_domains {
|
2015-12-23 00:08:15 +01:00
|
|
|
GIT_DOMAIN_NAME='gogs'
|
|
|
|
if grep -q "Gogs domain" $COMPLETION_FILE; then
|
|
|
|
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
|
|
|
|
fi
|
2015-12-11 10:14:33 +01:00
|
|
|
MICROBLOG_DOMAIN_NAME='microblog'
|
|
|
|
if grep -q "GNU Social domain" $COMPLETION_FILE; then
|
|
|
|
MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
|
|
|
|
fi
|
|
|
|
HUBZILLA_DOMAIN_NAME='hubzilla'
|
|
|
|
if grep -q "Hubzilla domain" $COMPLETION_FILE; then
|
|
|
|
HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
|
|
|
|
fi
|
|
|
|
FULLBLOG_DOMAIN_NAME='blog'
|
|
|
|
if grep -q "Blog domain" $COMPLETION_FILE; then
|
|
|
|
FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
|
|
|
|
fi
|
2015-12-23 00:08:15 +01:00
|
|
|
OWNCLOUD_DOMAIN_NAME='owncloud'
|
|
|
|
if grep -q "Owncloud domain" $COMPLETION_FILE; then
|
|
|
|
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
|
|
|
|
fi
|
2015-12-09 13:21:47 +01:00
|
|
|
}
|
2015-12-08 23:31:02 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
function mount_drive {
|
|
|
|
if [ $1 ]; then
|
|
|
|
USB_DRIVE=/dev/${1}1
|
|
|
|
fi
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# get the admin user
|
|
|
|
ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
|
|
|
|
if [ $2 ]; then
|
|
|
|
ADMIN_USERNAME=$2
|
|
|
|
fi
|
|
|
|
ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# check that the backup destination is available
|
|
|
|
if [ ! -b $USB_DRIVE ]; then
|
|
|
|
echo $"Please attach a USB drive"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# unmount if already mounted
|
|
|
|
umount -f $USB_MOUNT
|
|
|
|
if [ ! -d $USB_MOUNT ]; then
|
|
|
|
mkdir $USB_MOUNT
|
|
|
|
fi
|
|
|
|
if [ -f /dev/mapper/encrypted_usb ]; then
|
|
|
|
rm -rf /dev/mapper/encrypted_usb
|
|
|
|
fi
|
|
|
|
cryptsetup luksClose encrypted_usb
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# mount the encrypted backup drive
|
|
|
|
cryptsetup luksOpen $USB_DRIVE encrypted_usb
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
USB_DRIVE=/dev/mapper/encrypted_usb
|
|
|
|
fi
|
|
|
|
mount $USB_DRIVE $USB_MOUNT
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
echo $"There was a problem mounting the USB drive to $USB_MOUNT"
|
|
|
|
rm -rf $USB_MOUNT
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function unmount_drive {
|
|
|
|
sync
|
2015-12-08 12:40:41 +01:00
|
|
|
umount $USB_MOUNT
|
2015-12-08 22:18:31 +01:00
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
echo $"Unable to unmount the drive. This means that the backup did not work"
|
|
|
|
rm -rf $USB_MOUNT
|
|
|
|
exit 9
|
|
|
|
fi
|
2015-12-08 12:40:41 +01:00
|
|
|
rm -rf $USB_MOUNT
|
2015-12-08 22:18:31 +01:00
|
|
|
if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then
|
|
|
|
echo $"Unmount encrypted USB"
|
|
|
|
cryptsetup luksClose encrypted_usb
|
|
|
|
fi
|
|
|
|
if [ -f /dev/mapper/encrypted_usb ]; then
|
|
|
|
rm -rf /dev/mapper/encrypted_usb
|
|
|
|
fi
|
|
|
|
echo $"Backup to USB drive is complete. You can now unplug it."
|
|
|
|
}
|
2015-12-08 12:40:41 +01:00
|
|
|
|
|
|
|
function backup_database {
|
|
|
|
if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
|
|
|
|
echo $"No MariaDB password was given"
|
2015-12-23 00:08:15 +01:00
|
|
|
restart_site
|
2015-12-08 12:40:41 +01:00
|
|
|
exit 10
|
|
|
|
fi
|
|
|
|
if [ ! -d $USB_MOUNT/backup/${1} ]; then
|
|
|
|
mkdir -p $USB_MOUNT/backup/${1}
|
|
|
|
fi
|
|
|
|
if [ ! -d $USB_MOUNT/backup/${1}data ]; then
|
|
|
|
mkdir -p $USB_MOUNT/backup/${1}data
|
|
|
|
fi
|
|
|
|
if [ ! -d /root/temp${1}data ]; then
|
|
|
|
mkdir -p /root/temp${1}data
|
|
|
|
fi
|
|
|
|
echo $"Obtaining ${1} database backup"
|
|
|
|
mysqldump --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql
|
|
|
|
if [ ! -s /root/temp${1}data/${1}.sql ]; then
|
|
|
|
echo $"${1} database could not be saved"
|
|
|
|
shred -zu /root/temp${1}data/*
|
|
|
|
rm -rf /root/temp${1}data
|
|
|
|
umount $USB_MOUNT
|
|
|
|
rm -rf $USB_MOUNT
|
2015-12-23 00:08:15 +01:00
|
|
|
restart_site
|
2015-12-08 12:40:41 +01:00
|
|
|
exit 5
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_directory_to_usb {
|
|
|
|
if [ ! -d ${1} ]; then
|
|
|
|
echo $"WARNING: directory does not exist: ${1}"
|
|
|
|
else
|
|
|
|
BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
echo $"Backup key could not be found"
|
2015-12-23 00:08:15 +01:00
|
|
|
restart_site
|
2015-12-08 12:40:41 +01:00
|
|
|
exit 6
|
|
|
|
fi
|
|
|
|
MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
|
2015-12-08 18:41:37 +01:00
|
|
|
if [ ! -d $USB_MOUNT/backup/${2} ]; then
|
|
|
|
mkdir -p $USB_MOUNT/backup/${2}
|
|
|
|
fi
|
2015-12-08 12:40:41 +01:00
|
|
|
obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
|
|
|
|
obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
|
2015-12-17 17:13:36 +01:00
|
|
|
obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
umount $USB_MOUNT
|
|
|
|
rm -rf $USB_MOUNT
|
|
|
|
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
|
|
|
shred -zu ${1}/*
|
|
|
|
rm -rf ${1}
|
|
|
|
fi
|
2015-12-23 00:08:15 +01:00
|
|
|
restart_site
|
2015-12-17 17:13:36 +01:00
|
|
|
exit 71
|
|
|
|
fi
|
2015-12-08 12:40:41 +01:00
|
|
|
obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
umount $USB_MOUNT
|
|
|
|
rm -rf $USB_MOUNT
|
|
|
|
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
|
|
|
shred -zu ${1}/*
|
|
|
|
rm -rf ${1}
|
|
|
|
fi
|
2015-12-23 00:08:15 +01:00
|
|
|
restart_site
|
2015-12-08 12:40:41 +01:00
|
|
|
exit 7
|
|
|
|
fi
|
|
|
|
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
|
|
|
shred -zu ${1}/*
|
|
|
|
rm -rf ${1}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
function make_backup_directory {
|
|
|
|
# make a backup directory on the drive
|
|
|
|
if [ ! -d $USB_MOUNT/backup ]; then
|
|
|
|
mkdir $USB_MOUNT/backup
|
|
|
|
fi
|
|
|
|
if [ ! -d $USB_MOUNT/backup ]; then
|
|
|
|
echo $"There was a problem making the directory $USB_MOUNT/backup."
|
|
|
|
umount $USB_MOUNT
|
|
|
|
rm -rf $USB_MOUNT
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_storage_space_remaining {
|
|
|
|
# Check space remaining on the usb drive
|
|
|
|
used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}')
|
|
|
|
if [ $used_percent -gt 95 ]; then
|
|
|
|
echo $"Less than 5% of space remaining on backup drive"
|
|
|
|
umount $USB_MOUNT
|
|
|
|
rm -rf $USB_MOUNT
|
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
}
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
function backup_users {
|
|
|
|
# Backup user files
|
|
|
|
for d in /home/*/ ; do
|
|
|
|
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
|
|
|
if [[ $USERNAME != "git" ]]; then
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# Backup any gpg keys
|
|
|
|
if [ -d /home/$USERNAME/.gnupg ]; then
|
|
|
|
echo $"Backing up gpg keys for $USERNAME"
|
|
|
|
backup_directory_to_usb /home/$USERNAME/.gnupg gnupg/$USERNAME
|
|
|
|
fi
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# Backup any personal settings
|
|
|
|
if [ -d /home/$USERNAME/personal ]; then
|
|
|
|
echo $"Backing up personal settings for $USERNAME"
|
|
|
|
backup_directory_to_usb /home/$USERNAME/personal personal/$USERNAME
|
|
|
|
fi
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# Backup ssh keys
|
|
|
|
if [ -d /home/$USERNAME/.ssh ]; then
|
|
|
|
echo $"Backing up ssh keys for $USERNAME"
|
|
|
|
backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME
|
|
|
|
fi
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# Backup user configs
|
|
|
|
if [ -d /home/$USERNAME/.config ]; then
|
|
|
|
echo $"Backing up config files for $USERNAME"
|
|
|
|
backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME
|
2015-12-08 12:40:41 +01:00
|
|
|
fi
|
2015-12-08 22:18:31 +01:00
|
|
|
|
|
|
|
# Backup mutt
|
|
|
|
if [ -f /home/$USERNAME/.muttrc ]; then
|
|
|
|
echo $"Backing up Mutt settings for $USERNAME"
|
|
|
|
if [ ! -d /home/$USERNAME/tempbackup ]; then
|
|
|
|
mkdir -p /home/$USERNAME/tempbackup
|
|
|
|
fi
|
|
|
|
cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
|
|
|
|
if [ -f /etc/Muttrc ]; then
|
|
|
|
cp /etc/Muttrc /home/$USERNAME/tempbackup
|
|
|
|
fi
|
|
|
|
backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME
|
2015-12-08 12:40:41 +01:00
|
|
|
fi
|
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# Backup email
|
|
|
|
if [ -d /home/$USERNAME/Maildir ]; then
|
|
|
|
echo $"Creating an email archive for $USERNAME"
|
|
|
|
if [ ! -d /root/tempbackupemail/$USERNAME ]; then
|
|
|
|
mkdir -p /root/tempbackupemail/$USERNAME
|
|
|
|
fi
|
|
|
|
tar -czvf /root/tempbackupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir
|
|
|
|
echo $"Backing up emails for $USERNAME"
|
|
|
|
backup_directory_to_usb /root/tempbackupemail/$USERNAME mail/$USERNAME
|
2015-12-08 12:40:41 +01:00
|
|
|
fi
|
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# Backup spamassassin
|
|
|
|
if [ -d /home/$USERNAME/.spamassassin ]; then
|
|
|
|
echo $"Backing up spamassassin settings for $USERNAME"
|
|
|
|
backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME
|
|
|
|
fi
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
# Backup procmail
|
|
|
|
if [ -f /home/$USERNAME/.procmailrc ]; then
|
|
|
|
echo $"Backing up procmail settings for $USERNAME"
|
|
|
|
if [ ! -d /home/$USERNAME/tempbackup ]; then
|
|
|
|
mkdir -p /home/$USERNAME/tempbackup
|
|
|
|
fi
|
|
|
|
cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
|
|
|
|
backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME
|
2015-12-08 12:40:41 +01:00
|
|
|
fi
|
|
|
|
fi
|
2015-12-08 22:18:31 +01:00
|
|
|
done
|
|
|
|
}
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
function backup_directories {
|
2015-12-08 22:35:17 +01:00
|
|
|
# directories to be backed up (source,dest)
|
|
|
|
backup_dirs=(
|
2015-12-08 23:31:02 +01:00
|
|
|
"none, none, /etc/letsencrypt, letsencrypt"
|
|
|
|
"none, none, /var/lib/dokuwiki, wiki"
|
|
|
|
"none, none, /etc/dokuwiki, wiki2"
|
|
|
|
"none, none, /etc/ssl, ssl"
|
|
|
|
"none, none, /var/spool/mlmmj, mailinglist"
|
|
|
|
"none, none, /var/lib/prosody, xmpp"
|
|
|
|
"none, none, /etc/nginx/sites-available, web"
|
|
|
|
"none, none, /home/$ADMIN_USERNAME/.ipfs, ipfs"
|
|
|
|
"none, none, /var/cache/minidlna, dlna"
|
|
|
|
"/etc/owncloud, owncloud, /root/tempownclouddata, ownclouddata"
|
|
|
|
"none, none, /var/lib/owncloud, owncloud"
|
|
|
|
"none, none, /etc/owncloud, owncloud2"
|
|
|
|
"/home/git/go/src/github.com/gogits, gogs, /root/tempgogsdata, gogsdata"
|
|
|
|
"none, none, /home/git/go/src/github.com/gogits/gogs/custom, gogs"
|
|
|
|
"none, none, /home/git/gogs-repositories, gogsrepos"
|
|
|
|
"none, none, /home/git/.ssh, gogsssh"
|
|
|
|
"none, none, /var/lib/tox-bootstrapd, tox"
|
|
|
|
"/var/www/${MICROBLOG_DOMAIN_NAME}, gnusocial, /root/tempgnusocialdata, gnusocialdata"
|
|
|
|
"none, none, /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs, gnusocial"
|
|
|
|
"/var/www/${HUBZILLA_DOMAIN_NAME}, hubzilla, /root/temphubzilladata, hubzilladata"
|
|
|
|
"none, none, /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs, hubzilla"
|
|
|
|
"none, none, /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs, blog"
|
2015-12-08 22:35:17 +01:00
|
|
|
)
|
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
for dr in "${backup_dirs[@]}"
|
|
|
|
do
|
2015-12-08 23:31:02 +01:00
|
|
|
# if this directory exists then backup the given database
|
|
|
|
required_directory=$(echo $dr | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
2015-12-23 00:08:15 +01:00
|
|
|
database_name=$(echo $dr | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
|
|
|
|
|
|
|
if [[ "$database_name" == *"hubzilla"* ]]; then
|
|
|
|
suspend_site ${HUBZILLA_DOMAIN_NAME}
|
|
|
|
fi
|
|
|
|
if [[ "$database_name" == *"gnusocial"* ]]; then
|
|
|
|
suspend_site ${MICROBLOG_DOMAIN_NAME}
|
|
|
|
fi
|
|
|
|
if [[ "$database_name" == *"owncloud"* ]]; then
|
|
|
|
suspend_site ${OWNCLOUD_DOMAIN_NAME}
|
|
|
|
fi
|
|
|
|
if [[ "$database_name" == *"gogs"* ]]; then
|
|
|
|
suspend_site ${GIT_DOMAIN_NAME}
|
|
|
|
fi
|
|
|
|
|
2015-12-08 23:31:02 +01:00
|
|
|
if [[ $required_directory != "none" ]]; then
|
|
|
|
if [ -d $required_directory ]; then
|
|
|
|
if [[ $database_name != "none" ]]; then
|
|
|
|
backup_database $database_name
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# if this directory exists then back it up to the given destination
|
|
|
|
source_directory=$(echo $dr | awk -F ',' '{print $3}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
2015-12-08 22:18:31 +01:00
|
|
|
if [ -d $source_directory ]; then
|
2015-12-08 23:31:02 +01:00
|
|
|
dest_directory=$(echo $dr | awk -F ',' '{print $4}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
2015-12-08 22:18:31 +01:00
|
|
|
echo $"Backing up $source_directory to $dest_directory"
|
|
|
|
backup_directory_to_usb $source_directory $dest_directory
|
|
|
|
fi
|
2015-12-23 00:08:15 +01:00
|
|
|
|
|
|
|
restart_site
|
2015-12-08 22:18:31 +01:00
|
|
|
done
|
|
|
|
}
|
2015-12-08 12:40:41 +01:00
|
|
|
|
2015-12-09 10:45:06 +01:00
|
|
|
function remove_backup_directory {
|
|
|
|
if [ $1 ]; then
|
|
|
|
if [[ $1 == "remove" ]]; then
|
2015-12-10 17:09:04 +01:00
|
|
|
if [ -d $USB_MOUNT/backup ]; then
|
2015-12-09 10:45:06 +01:00
|
|
|
rm -rf $USB_MOUNT/backup
|
|
|
|
echo $'Existing backup directory removed'
|
|
|
|
unmount_drive
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-12-11 10:14:33 +01:00
|
|
|
function prepare_directories {
|
|
|
|
# Some miscellaneous preparation for backing up directories
|
|
|
|
if [ -d /home/git/go/src/github.com/gogits ]; then
|
|
|
|
mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
|
|
|
|
fi
|
|
|
|
if [ -d /var/lib/tox-bootstrapd ]; then
|
|
|
|
cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
|
|
|
|
if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
|
|
|
|
rm -rf /var/lib/tox-bootstrapd/Maildir
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_configuration {
|
|
|
|
echo $"Backing up ${PROJECT_NAME} configuration files"
|
|
|
|
if [ ! -d /root/tempbackupconfig ]; then
|
|
|
|
mkdir -p /root/tempbackupconfig
|
|
|
|
fi
|
|
|
|
cp -f $CONFIG_FILE /root/tempbackupconfig
|
|
|
|
cp -f $COMPLETION_FILE /root/tempbackupconfig
|
2015-12-11 17:25:43 +01:00
|
|
|
if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
|
|
|
|
cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
|
|
|
|
fi
|
2015-12-11 10:14:33 +01:00
|
|
|
backup_directory_to_usb /root/tempbackupconfig config
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_admin_readme {
|
|
|
|
if [ -f /home/$ADMIN_USERNAME/README ]; then
|
|
|
|
echo $"Backing up README"
|
|
|
|
if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then
|
|
|
|
mkdir -p /home/$ADMIN_USERNAME/tempbackup
|
|
|
|
fi
|
|
|
|
cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup
|
|
|
|
backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_voip {
|
|
|
|
if [ -f /etc/mumble-server.ini ]; then
|
|
|
|
echo $"Backing up VoIP settings"
|
|
|
|
if [ ! -d /root/tempvoipbackup ]; then
|
|
|
|
mkdir -p /root/tempvoipbackup
|
|
|
|
fi
|
|
|
|
cp -f /etc/mumble-server.ini /root/tempvoipbackup
|
|
|
|
cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
|
|
|
|
cp -f /etc/sipwitch.conf /root/tempvoipbackup
|
|
|
|
backup_directory_to_usb /root/tempvoipbackup voip
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_mariadb {
|
|
|
|
if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
|
|
|
|
if [ ! -d /root/tempmariadb ]; then
|
|
|
|
mkdir /root/tempmariadb
|
|
|
|
fi
|
|
|
|
mysqldump --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql
|
|
|
|
if [ ! -s /root/tempmariadb/mysql.sql ]; then
|
|
|
|
echo $"Unable to backup mysql settings"
|
|
|
|
rm -rf /root/tempmariadb
|
|
|
|
umount $USB_MOUNT
|
|
|
|
rm -rf $USB_MOUNT
|
|
|
|
exit 8
|
|
|
|
fi
|
|
|
|
echo "$DATABASE_PASSWORD" > /root/tempmariadb/db
|
|
|
|
chmod 400 /root/tempmariadb/db
|
|
|
|
backup_directory_to_usb /root/tempmariadb mariadb
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-12-11 17:25:43 +01:00
|
|
|
function valid_backup_destination {
|
|
|
|
destination_dir="$1"
|
|
|
|
is_valid="yes"
|
|
|
|
|
|
|
|
if [[ "$destination_dir" == "hubzilla" || \
|
|
|
|
"$destination_dir" == "hubzilladata" || \
|
|
|
|
"$destination_dir" == "gogs" || \
|
|
|
|
"$destination_dir" == "gogsrepos" || \
|
|
|
|
"$destination_dir" == "gogsssh" || \
|
|
|
|
"$destination_dir" == "gnusocial" || \
|
|
|
|
"$destination_dir" == "gnusocialdata" || \
|
|
|
|
"$destination_dir" == "mariadb" || \
|
|
|
|
"$destination_dir" == "config" || \
|
|
|
|
"$destination_dir" == "letsencrypt" || \
|
|
|
|
"$destination_dir" == "wiki" || \
|
|
|
|
"$destination_dir" == "wiki2" || \
|
|
|
|
"$destination_dir" == "xmpp" || \
|
|
|
|
"$destination_dir" == "ipfs" || \
|
|
|
|
"$destination_dir" == "dlna" || \
|
|
|
|
"$destination_dir" == "tox" || \
|
|
|
|
"$destination_dir" == "ssl" || \
|
|
|
|
"$destination_dir" == "blog" || \
|
|
|
|
"$destination_dir" == "owncloud" || \
|
|
|
|
"$destination_dir" == "owncloud2" || \
|
|
|
|
"$destination_dir" == "ownclouddata" || \
|
|
|
|
"$destination_dir" == "mailinglist" ]]; then
|
|
|
|
is_valid="no"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $is_valid
|
|
|
|
}
|
|
|
|
|
2015-12-11 17:06:28 +01:00
|
|
|
function backup_extra_directories {
|
|
|
|
if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $"Backing up some additional directories"
|
|
|
|
while read backup_line
|
|
|
|
do
|
|
|
|
backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
|
|
|
if [ -d "$backup_dir" ]; then
|
|
|
|
destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
2015-12-11 17:25:43 +01:00
|
|
|
if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
|
|
|
|
backup_directory_to_usb "$backup_dir" "$destination_dir"
|
|
|
|
else
|
|
|
|
echo $"WARNING: The backup directory $destination_dir is already used."
|
|
|
|
echo $"Choose a different destination name for backing up $backup_dir"
|
|
|
|
fi
|
2015-12-11 17:06:28 +01:00
|
|
|
else
|
|
|
|
echo $"WARNING: Directory $backup_dir does not exist"
|
|
|
|
fi
|
|
|
|
done <$BACKUP_EXTRA_DIRECTORIES
|
|
|
|
}
|
|
|
|
|
2015-12-09 10:45:06 +01:00
|
|
|
# has the remove option been set ?
|
|
|
|
remove_option=$2
|
|
|
|
if [[ $1 == "remove" ]]; then
|
|
|
|
remove_option=$1
|
|
|
|
fi
|
|
|
|
|
2015-12-08 22:18:31 +01:00
|
|
|
mount_drive $1 $2
|
2015-12-09 10:45:06 +01:00
|
|
|
remove_backup_directory $remove_option
|
2015-12-08 22:18:31 +01:00
|
|
|
make_backup_directory
|
|
|
|
check_storage_space_remaining
|
2015-12-09 13:21:47 +01:00
|
|
|
update_domains
|
2015-12-08 22:18:31 +01:00
|
|
|
backup_users
|
2015-12-11 10:14:33 +01:00
|
|
|
prepare_directories
|
2015-12-08 23:31:02 +01:00
|
|
|
backup_directories
|
2015-12-11 10:14:33 +01:00
|
|
|
backup_configuration
|
|
|
|
backup_admin_readme
|
|
|
|
backup_voip
|
|
|
|
backup_mariadb
|
2015-12-11 17:06:28 +01:00
|
|
|
backup_extra_directories
|
2015-12-08 22:18:31 +01:00
|
|
|
unmount_drive
|
|
|
|
|
2015-12-08 12:40:41 +01:00
|
|
|
exit 0
|