Backup and restore of syncthing

Replacing owncloud
This commit is contained in:
Bob Mottram 2016-04-10 10:32:25 +01:00
parent f902b04d46
commit 37b0fd0e12
4 changed files with 1070 additions and 982 deletions

View File

@ -100,10 +100,6 @@ function update_domains {
if grep -q "Blog domain" $COMPLETION_FILE; then if grep -q "Blog domain" $COMPLETION_FILE; then
FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
fi fi
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
MEDIAGOBLIN_DOMAIN_NAME='mediagoblin' MEDIAGOBLIN_DOMAIN_NAME='mediagoblin'
if grep -q "Mediagoblin domain" $COMPLETION_FILE; then if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
@ -299,280 +295,295 @@ function backup_users {
backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME
fi fi
# Backup user configs # Backup syncthing
if [ -d /home/$USERNAME/.config ]; then if [ -d /home/$USERNAME/Sync ]; then
echo $"Backing up config files for $USERNAME" echo $"Backing up syncthing files for $USERNAME"
backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME
fi # ensure that device IDs will be backed up as part of user config settings
if [ ! -d /home/$USERNAME/.config/syncthing ]; then
mkdir -p /home/$USERNAME/.config/syncthing
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
fi
if [ -f /home/$USERNAME/.syncthing-server-id ]; then
cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
fi
if [ -f /home/$USERNAME/.syncthingids ]; then
cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
fi
fi
# 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
fi
# Backup user local
if [ -d /home/$USERNAME/.local ]; then
echo $"Backing up local files for $USERNAME"
backup_directory_to_usb /home/$USERNAME/.local local/$USERNAME
fi
# Backup user local # Backup mutt
if [ -d /home/$USERNAME/.local ]; then if [ -f /home/$USERNAME/.muttrc ]; then
echo $"Backing up local files for $USERNAME" echo $"Backing up Mutt settings for $USERNAME"
backup_directory_to_usb /home/$USERNAME/.local local/$USERNAME if [ ! -d /home/$USERNAME/tempbackup ]; then
fi 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
fi
# Backup mutt # Backup email
if [ -f /home/$USERNAME/.muttrc ]; then if [ -d /home/$USERNAME/Maildir ]; then
echo $"Backing up Mutt settings for $USERNAME" echo $"Creating an email archive for $USERNAME"
if [ ! -d /home/$USERNAME/tempbackup ]; then if [ ! -d /root/tempbackupemail/$USERNAME ]; then
mkdir -p /home/$USERNAME/tempbackup mkdir -p /root/tempbackupemail/$USERNAME
fi fi
cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup tar -czvf /root/tempbackupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir
if [ -f /etc/Muttrc ]; then echo $"Backing up emails for $USERNAME"
cp /etc/Muttrc /home/$USERNAME/tempbackup backup_directory_to_usb /root/tempbackupemail/$USERNAME mail/$USERNAME
fi fi
backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME
fi
# Backup email # Backup spamassassin
if [ -d /home/$USERNAME/Maildir ]; then if [ -d /home/$USERNAME/.spamassassin ]; then
echo $"Creating an email archive for $USERNAME" echo $"Backing up spamassassin settings for $USERNAME"
if [ ! -d /root/tempbackupemail/$USERNAME ]; then backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME
mkdir -p /root/tempbackupemail/$USERNAME fi
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
fi
# Backup spamassassin # Backup procmail
if [ -d /home/$USERNAME/.spamassassin ]; then if [ -f /home/$USERNAME/.procmailrc ]; then
echo $"Backing up spamassassin settings for $USERNAME" echo $"Backing up procmail settings for $USERNAME"
backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME if [ ! -d /home/$USERNAME/tempbackup ]; then
fi mkdir -p /home/$USERNAME/tempbackup
fi
# Backup procmail cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
if [ -f /home/$USERNAME/.procmailrc ]; then backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME
echo $"Backing up procmail settings for $USERNAME" fi
if [ ! -d /home/$USERNAME/tempbackup ]; then fi
mkdir -p /home/$USERNAME/tempbackup done
fi
cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME
fi
fi
done
} }
function backup_directories { function backup_directories {
# directories to be backed up (source,dest) # directories to be backed up (source,dest)
backup_dirs=( backup_dirs=(
"none, none, /etc/letsencrypt, letsencrypt" "none, none, /etc/letsencrypt, letsencrypt"
"none, none, /var/lib/dokuwiki, wiki" "none, none, /var/lib/dokuwiki, wiki"
"none, none, /etc/dokuwiki, wiki2" "none, none, /etc/dokuwiki, wiki2"
"none, none, /etc/ssl, ssl" "none, none, /etc/ssl, ssl"
"/etc/share/tt-rss, ttrss, /root/tempttrssdata, ttrss" "/etc/share/tt-rss, ttrss, /root/tempttrssdata, ttrss"
"none, none, /var/spool/mlmmj, mailinglist" "none, none, /var/spool/mlmmj, mailinglist"
"none, none, /var/lib/prosody, xmpp" "none, none, /var/lib/prosody, xmpp"
"none, none, /etc/nginx/sites-available, web" "none, none, /etc/nginx/sites-available, web"
"none, none, /home/$ADMIN_USERNAME/.ipfs, ipfs" "none, none, /home/$ADMIN_USERNAME/.ipfs, ipfs"
"none, none, /var/cache/minidlna, dlna" "none, none, /var/cache/minidlna, dlna"
"/home/git/go/src/github.com/gogits, gogs, /root/tempgogsdata, gogsdata" "/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/go/src/github.com/gogits/gogs/custom, gogs"
"none, none, /home/git/gogs-repositories, gogsrepos" "none, none, /home/git/gogs-repositories, gogsrepos"
"none, none, /home/git/.ssh, gogsssh" "none, none, /home/git/.ssh, gogsssh"
"none, none, /var/lib/tox-bootstrapd, tox" "none, none, /var/lib/tox-bootstrapd, tox"
"/var/www/${MICROBLOG_DOMAIN_NAME}, gnusocial, /root/tempgnusocialdata, gnusocialdata" "/var/www/${MICROBLOG_DOMAIN_NAME}, gnusocial, /root/tempgnusocialdata, gnusocialdata"
"none, none, /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs, gnusocial" "none, none, /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs, gnusocial"
"/var/www/owncloud, owncloud, /root/tempownclouddata, ownclouddata" "none, none, /var/lib/syncthing/SyncShared, syncthingshared"
"none, none, /var/www/owncloud/data, owncloudfiles" "none, none, /root/.config/syncthing, syncthingconfig"
"none, none, /var/www/owncloud/config, owncloudconfig" "/var/www/${HUBZILLA_DOMAIN_NAME}, hubzilla, /root/temphubzilladata, hubzilladata"
"/var/www/${HUBZILLA_DOMAIN_NAME}, hubzilla, /root/temphubzilladata, hubzilladata" "none, none, /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs, hubzilla"
"none, none, /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs, hubzilla" "none, none, /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs, blog"
"none, none, /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs, blog" "none, none, /var/lib/tor, tor"
"none, none, /var/lib/tor, tor" "none, none, /var/www/${MEDIAGOBLIN_DOMAIN_NAME}/htdocs, mediagoblin"
"none, none, /var/www/${MEDIAGOBLIN_DOMAIN_NAME}/htdocs, mediagoblin" )
)
for dr in "${backup_dirs[@]}" for dr in "${backup_dirs[@]}"
do do
# if this directory exists then backup the given database # if this directory exists then backup the given database
required_directory=$(echo $dr | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') required_directory=$(echo $dr | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
database_name=$(echo $dr | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') database_name=$(echo $dr | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [[ "$database_name" == *"hubzilla"* ]]; then if [[ "$database_name" == *"hubzilla"* ]]; then
suspend_site ${HUBZILLA_DOMAIN_NAME} suspend_site ${HUBZILLA_DOMAIN_NAME}
fi fi
if [[ "$database_name" == *"gnusocial"* ]]; then if [[ "$database_name" == *"gnusocial"* ]]; then
suspend_site ${MICROBLOG_DOMAIN_NAME} suspend_site ${MICROBLOG_DOMAIN_NAME}
fi fi
if [[ "$database_name" == *"owncloud"* ]]; then if [[ "$database_name" == *"gogs"* ]]; then
suspend_site ${OWNCLOUD_DOMAIN_NAME} suspend_site ${GIT_DOMAIN_NAME}
fi fi
if [[ "$database_name" == *"gogs"* ]]; then if [[ "$database_name" == *"ttrss"* ]]; then
suspend_site ${GIT_DOMAIN_NAME} suspend_site ${RSS_READER_DOMAIN_NAME}
fi fi
if [[ "$database_name" == *"ttrss"* ]]; then
suspend_site ${RSS_READER_DOMAIN_NAME}
fi
if [[ $required_directory != "none" ]]; then if [[ $required_directory != "none" ]]; then
if [ -d $required_directory ]; then if [ -d $required_directory ]; then
if [[ $database_name != "none" ]]; then if [[ $database_name != "none" ]]; then
backup_database $database_name backup_database $database_name
fi fi
fi fi
fi fi
# if this directory exists then back it up to the given destination # 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:]]*$//') source_directory=$(echo $dr | awk -F ',' '{print $3}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [ -d $source_directory ]; then if [ -d $source_directory ]; then
dest_directory=$(echo $dr | awk -F ',' '{print $4}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') dest_directory=$(echo $dr | awk -F ',' '{print $4}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
echo $"Backing up $source_directory to $dest_directory" echo $"Backing up $source_directory to $dest_directory"
backup_directory_to_usb $source_directory $dest_directory backup_directory_to_usb $source_directory $dest_directory
fi fi
restart_site restart_site
done done
} }
function remove_backup_directory { function remove_backup_directory {
if [ $1 ]; then if [ $1 ]; then
if [[ $1 == "remove" ]]; then if [[ $1 == "remove" ]]; then
if [ -d $USB_MOUNT/backup ]; then if [ -d $USB_MOUNT/backup ]; then
rm -rf $USB_MOUNT/backup rm -rf $USB_MOUNT/backup
echo $'Existing backup directory removed' echo $'Existing backup directory removed'
unmount_drive unmount_drive
exit 0 exit 0
fi fi
fi fi
fi fi
} }
function prepare_directories { function prepare_directories {
# Some miscellaneous preparation for backing up directories # Some miscellaneous preparation for backing up directories
if [ -d /home/git/go/src/github.com/gogits ]; then if [ -d /home/git/go/src/github.com/gogits ]; then
mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
fi fi
if [ -d /var/lib/tox-bootstrapd ]; then if [ -d /var/lib/tox-bootstrapd ]; then
cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
if [ -d /var/lib/tox-bootstrapd/Maildir ]; then if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
rm -rf /var/lib/tox-bootstrapd/Maildir rm -rf /var/lib/tox-bootstrapd/Maildir
fi fi
fi fi
} }
function backup_configuration { function backup_configuration {
echo $"Backing up ${PROJECT_NAME} configuration files" echo $"Backing up ${PROJECT_NAME} configuration files"
if [ ! -d /root/tempbackupconfig ]; then if [ ! -d /root/tempbackupconfig ]; then
mkdir -p /root/tempbackupconfig mkdir -p /root/tempbackupconfig
fi fi
cp -f $CONFIG_FILE /root/tempbackupconfig cp -f $CONFIG_FILE /root/tempbackupconfig
cp -f $COMPLETION_FILE /root/tempbackupconfig cp -f $COMPLETION_FILE /root/tempbackupconfig
if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
fi fi
# nginx password hashes # nginx password hashes
if [ -f /etc/nginx/.htpasswd ]; then if [ -f /etc/nginx/.htpasswd ]; then
cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd
fi fi
backup_directory_to_usb /root/tempbackupconfig config backup_directory_to_usb /root/tempbackupconfig config
} }
function backup_admin_readme { function backup_admin_readme {
if [ -f /home/$ADMIN_USERNAME/README ]; then if [ -f /home/$ADMIN_USERNAME/README ]; then
echo $"Backing up README" echo $"Backing up README"
if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then
mkdir -p /home/$ADMIN_USERNAME/tempbackup mkdir -p /home/$ADMIN_USERNAME/tempbackup
fi fi
cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup
backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme
fi fi
} }
function backup_voip { function backup_voip {
if [ -f /etc/mumble-server.ini ]; then if [ -f /etc/mumble-server.ini ]; then
echo $"Backing up VoIP settings" echo $"Backing up VoIP settings"
if [ ! -d /root/tempvoipbackup ]; then if [ ! -d /root/tempvoipbackup ]; then
mkdir -p /root/tempvoipbackup mkdir -p /root/tempvoipbackup
fi fi
cp -f /etc/mumble-server.ini /root/tempvoipbackup cp -f /etc/mumble-server.ini /root/tempvoipbackup
cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
cp -f /etc/sipwitch.conf /root/tempvoipbackup cp -f /etc/sipwitch.conf /root/tempvoipbackup
backup_directory_to_usb /root/tempvoipbackup voip backup_directory_to_usb /root/tempvoipbackup voip
fi fi
} }
function backup_mariadb { function backup_mariadb {
if [ ${#DATABASE_PASSWORD} -gt 1 ]; then if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
if [ ! -d /root/tempmariadb ]; then if [ ! -d /root/tempmariadb ]; then
mkdir /root/tempmariadb mkdir /root/tempmariadb
fi fi
mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql
if [ ! -s /root/tempmariadb/mysql.sql ]; then if [ ! -s /root/tempmariadb/mysql.sql ]; then
echo $"Unable to backup mysql settings" echo $"Unable to backup mysql settings"
rm -rf /root/tempmariadb rm -rf /root/tempmariadb
umount $USB_MOUNT umount $USB_MOUNT
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
exit 8 exit 8
fi fi
echo "$DATABASE_PASSWORD" > /root/tempmariadb/db echo "$DATABASE_PASSWORD" > /root/tempmariadb/db
chmod 400 /root/tempmariadb/db chmod 400 /root/tempmariadb/db
backup_directory_to_usb /root/tempmariadb mariadb backup_directory_to_usb /root/tempmariadb mariadb
fi fi
} }
function valid_backup_destination { function valid_backup_destination {
destination_dir="$1" destination_dir="$1"
is_valid="yes" is_valid="yes"
if [[ "$destination_dir" == "hubzilla" || \ if [[ "$destination_dir" == "hubzilla" || \
"$destination_dir" == "hubzilladata" || \ "$destination_dir" == "hubzilladata" || \
"$destination_dir" == "gogs" || \ "$destination_dir" == "gogs" || \
"$destination_dir" == "gogsrepos" || \ "$destination_dir" == "gogsrepos" || \
"$destination_dir" == "gogsssh" || \ "$destination_dir" == "gogsssh" || \
"$destination_dir" == "gnusocial" || \ "$destination_dir" == "gnusocial" || \
"$destination_dir" == "gnusocialdata" || \ "$destination_dir" == "gnusocialdata" || \
"$destination_dir" == "mariadb" || \ "$destination_dir" == "mariadb" || \
"$destination_dir" == "config" || \ "$destination_dir" == "config" || \
"$destination_dir" == "letsencrypt" || \ "$destination_dir" == "letsencrypt" || \
"$destination_dir" == "wiki" || \ "$destination_dir" == "wiki" || \
"$destination_dir" == "wiki2" || \ "$destination_dir" == "wiki2" || \
"$destination_dir" == "xmpp" || \ "$destination_dir" == "xmpp" || \
"$destination_dir" == "ipfs" || \ "$destination_dir" == "ipfs" || \
"$destination_dir" == "dlna" || \ "$destination_dir" == "dlna" || \
"$destination_dir" == "tox" || \ "$destination_dir" == "tox" || \
"$destination_dir" == "ssl" || \ "$destination_dir" == "ssl" || \
"$destination_dir" == "ttrss" || \ "$destination_dir" == "ttrss" || \
"$destination_dir" == "blog" || \ "$destination_dir" == "blog" || \
"$destination_dir" == "owncloudfiles" || \ "$destination_dir" == "syncthingconfig" || \
"$destination_dir" == "owncloudconfig" || \ "$destination_dir" == "syncthingshared" || \
"$destination_dir" == "ownclouddata" || \ "$destination_dir" == "syncthing" || \
"$destination_dir" == "mediagoblin" || \ "$destination_dir" == "mediagoblin" || \
"$destination_dir" == "mailinglist" ]]; then "$destination_dir" == "mailinglist" ]]; then
is_valid="no" is_valid="no"
fi fi
echo $is_valid echo $is_valid
} }
function backup_extra_directories { function backup_extra_directories {
if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
return return
fi fi
echo $"Backing up some additional directories" echo $"Backing up some additional directories"
while read backup_line while read backup_line
do do
backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [ -d "$backup_dir" ]; then if [ -d "$backup_dir" ]; then
destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
backup_directory_to_usb "$backup_dir" "$destination_dir" backup_directory_to_usb "$backup_dir" "$destination_dir"
else else
echo $"WARNING: The backup directory $destination_dir is already used." echo $"WARNING: The backup directory $destination_dir is already used."
echo $"Choose a different destination name for backing up $backup_dir" echo $"Choose a different destination name for backing up $backup_dir"
fi fi
else else
echo $"WARNING: Directory $backup_dir does not exist" echo $"WARNING: Directory $backup_dir does not exist"
fi fi
done <$BACKUP_EXTRA_DIRECTORIES done <$BACKUP_EXTRA_DIRECTORIES
} }
# has the remove option been set ? # has the remove option been set ?
remove_option=$2 remove_option=$2
if [[ $1 == "remove" ]]; then if [[ $1 == "remove" ]]; then
remove_option=$1 remove_option=$1
fi fi
mount_drive $1 $2 mount_drive $1 $2

View File

@ -202,6 +202,25 @@ function backup_users {
backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME
fi fi
# syncthing files
if [ -d /home/$USERNAME/Sync ]; then
echo $"Backing up syncthing files for $USERNAME"
backup_directory_to_friend /home/$USERNAME/Sync syncthing/$USERNAME
# ensure that device IDs will be backed up as part of user config settings
if [ ! -d /home/$USERNAME/.config/syncthing ]; then
mkdir -p /home/$USERNAME/.config/syncthing
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
fi
if [ -f /home/$USERNAME/.syncthing-server-id ]; then
cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
fi
if [ -f /home/$USERNAME/.syncthingids ]; then
cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
fi
fi
# config files # config files
if [ -d /home/$USERNAME/.config ]; then if [ -d /home/$USERNAME/.config ]; then
echo $"Backing up config files for $USERNAME" echo $"Backing up config files for $USERNAME"
@ -326,18 +345,14 @@ function backup_hubzilla {
fi fi
} }
function backup_owncloud { function backup_syncthing {
if [ -d /etc/owncloud ]; then if [ -d /root/.config/syncthing ]; then
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}') echo $"Backing up syncthing configuration"
suspend_site ${OWNCLOUD_DOMAIN_NAME} backup_directory_to_friend /root/.config/syncthing syncthingconfig
backup_database_to_friend owncloud fi
backup_directory_to_friend /root/tempownclouddata ownclouddata if [ -d /var/lib/syncthing/SyncShared ]; then
echo $"Backing up Owncloud data" echo $"Backing up syncthing shared files"
if [ -d /var/www/owncloud/data ]; then backup_directory_to_friend /var/lib/syncthing/SyncShared syncthingshared
backup_directory_to_friend /var/www/owncloud/data owncloudfiles
fi
backup_directory_to_friend /var/www/owncloud/config owncloudconfig
restart_site
fi fi
} }
@ -566,9 +581,9 @@ function valid_backup_destination {
"$destination_dir" == "tox" || \ "$destination_dir" == "tox" || \
"$destination_dir" == "ssl" || \ "$destination_dir" == "ssl" || \
"$destination_dir" == "blog" || \ "$destination_dir" == "blog" || \
"$destination_dir" == "owncloudfiles" || \ "$destination_dir" == "syncthing" || \
"$destination_dir" == "owncloudconfig" || \ "$destination_dir" == "syncthingconfig" || \
"$destination_dir" == "ownclouddata" || \ "$destination_dir" == "syncthingshared" || \
"$destination_dir" == "mailinglist" ]]; then "$destination_dir" == "mailinglist" ]]; then
is_valid="no" is_valid="no"
fi fi
@ -612,7 +627,7 @@ if [[ $TEST_MODE == "no" ]]; then
backup_gnusocial backup_gnusocial
backup_rss_reader backup_rss_reader
backup_hubzilla backup_hubzilla
backup_owncloud backup_syncthing
backup_mediagoblin backup_mediagoblin
backup_gogs backup_gogs
backup_wiki backup_wiki

File diff suppressed because it is too large Load Diff

View File

@ -693,48 +693,80 @@ function restore_hubzilla {
fi fi
} }
function restore_owncloud { function restore_syncthing {
if [[ $RESTORE_APP != 'all' ]]; then if [[ $RESTORE_APP != 'all' ]]; then
if [[ $RESTORE_APP != 'owncloud' ]]; then if [[ $RESTORE_APP != 'syncthing' ]]; then
return return
fi fi
fi fi
OWNCLOUD_PATH=/var/www/owncloud
if grep -q "Owncloud domain" $COMPLETION_FILE; then
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
restore_database_from_friend owncloud $OWNCLOUD_DOMAIN_NAME
if [ -d $SERVER_DIRECTORY/backup/owncloudfiles ]; then if [ -f /etc/systemd/system/syncthing.service ]; then
echo $"Restoring Owncloud installation" systemctl stop syncthing
restore_directory_from_friend /root/tempowncloudfiles owncloudfiles systemctl stop cron
cp -r /root/tempowncloudfiles/* / fi
if [ ! "$?" = "0" ]; then
exit 1458 if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
fi echo $"Restoring syncthing configuration"
rm -rf /root/tempowncloudfiles restore_directory_from_friend /root/tempsyncthingconfig syncthingconfig
cp -r /root/tempsyncthingconfig/* /
if [ ! "$?" = "0" ]; then
unmount_drive
systemctl start syncthing
systemctl start cron
exit 6833
fi fi
rm -rf /root/tempsyncthingconfig
fi
if [ -d $SERVER_DIRECTORY/backup/owncloudconfig ]; then if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
echo $"Restoring Owncloud installation" echo $"Restoring syncthing shared files"
restore_directory_from_friend /root/tempowncloudconfig owncloudconfig restore_directory_from_friend /root/tempsyncthingshared syncthingshared
cp -r /root/tempowncloudconfig/* / cp -r /root/tempsyncthingshared/* /
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
exit 2571 unmount_drive
fi systemctl start syncthing
rm -rf /root/tempowncloudconfig systemctl start cron
exit 37904
fi fi
rm -rf /root/tempsyncthingshared
fi
chown -R www-data:www-data $OWNCLOUD_PATH if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
chown root:root $OWNCLOUD_PATH/config/config.php for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
# re-index files
for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
$OWNCLOUD_PATH/occ files:scan $USERNAME if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME
fi
echo $"Restoring syncthing files for $USERNAME"
restore_directory_from_friend /root/tempsyncthing syncthing/$USERNAME
cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempsyncthing
unmount_drive
systemctl start syncthing
systemctl start cron
exit 68438
fi
rm -rf /root/tempsyncthing
# restore device IDs from config settings
if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
fi
if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
fi
fi fi
done done
fi fi
if [ -f /etc/systemd/system/syncthing.service ]; then
systemctl start syncthing
systemctl start cron
fi
} }
function restore_mediagoblin { function restore_mediagoblin {
@ -1014,7 +1046,7 @@ restore_xmpp
restore_gnu_social restore_gnu_social
restore_hubzilla restore_hubzilla
restore_rss_reader restore_rss_reader
restore_owncloud restore_syncthing
restore_mediagoblin restore_mediagoblin
restore_gogs restore_gogs
restore_wiki restore_wiki