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
FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
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'
if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
@ -299,6 +295,25 @@ function backup_users {
backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME
fi
# Backup syncthing
if [ -d /home/$USERNAME/Sync ]; then
echo $"Backing up syncthing files for $USERNAME"
backup_directory_to_usb /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
# Backup user configs
if [ -d /home/$USERNAME/.config ]; then
echo $"Backing up config files for $USERNAME"
@ -374,9 +389,8 @@ function backup_directories {
"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/owncloud, owncloud, /root/tempownclouddata, ownclouddata"
"none, none, /var/www/owncloud/data, owncloudfiles"
"none, none, /var/www/owncloud/config, owncloudconfig"
"none, none, /var/lib/syncthing/SyncShared, syncthingshared"
"none, none, /root/.config/syncthing, syncthingconfig"
"/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"
@ -396,9 +410,6 @@ function backup_directories {
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
@ -535,9 +546,9 @@ function valid_backup_destination {
"$destination_dir" == "ssl" || \
"$destination_dir" == "ttrss" || \
"$destination_dir" == "blog" || \
"$destination_dir" == "owncloudfiles" || \
"$destination_dir" == "owncloudconfig" || \
"$destination_dir" == "ownclouddata" || \
"$destination_dir" == "syncthingconfig" || \
"$destination_dir" == "syncthingshared" || \
"$destination_dir" == "syncthing" || \
"$destination_dir" == "mediagoblin" || \
"$destination_dir" == "mailinglist" ]]; then
is_valid="no"

View File

@ -202,6 +202,25 @@ function backup_users {
backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME
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
if [ -d /home/$USERNAME/.config ]; then
echo $"Backing up config files for $USERNAME"
@ -326,18 +345,14 @@ function backup_hubzilla {
fi
}
function backup_owncloud {
if [ -d /etc/owncloud ]; then
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
suspend_site ${OWNCLOUD_DOMAIN_NAME}
backup_database_to_friend owncloud
backup_directory_to_friend /root/tempownclouddata ownclouddata
echo $"Backing up Owncloud data"
if [ -d /var/www/owncloud/data ]; then
backup_directory_to_friend /var/www/owncloud/data owncloudfiles
function backup_syncthing {
if [ -d /root/.config/syncthing ]; then
echo $"Backing up syncthing configuration"
backup_directory_to_friend /root/.config/syncthing syncthingconfig
fi
backup_directory_to_friend /var/www/owncloud/config owncloudconfig
restart_site
if [ -d /var/lib/syncthing/SyncShared ]; then
echo $"Backing up syncthing shared files"
backup_directory_to_friend /var/lib/syncthing/SyncShared syncthingshared
fi
}
@ -566,9 +581,9 @@ function valid_backup_destination {
"$destination_dir" == "tox" || \
"$destination_dir" == "ssl" || \
"$destination_dir" == "blog" || \
"$destination_dir" == "owncloudfiles" || \
"$destination_dir" == "owncloudconfig" || \
"$destination_dir" == "ownclouddata" || \
"$destination_dir" == "syncthing" || \
"$destination_dir" == "syncthingconfig" || \
"$destination_dir" == "syncthingshared" || \
"$destination_dir" == "mailinglist" ]]; then
is_valid="no"
fi
@ -612,7 +627,7 @@ if [[ $TEST_MODE == "no" ]]; then
backup_gnusocial
backup_rss_reader
backup_hubzilla
backup_owncloud
backup_syncthing
backup_mediagoblin
backup_gogs
backup_wiki

View File

@ -57,7 +57,6 @@ DATABASE_PASSWORD=$(cat /root/dbpass)
MICROBLOG_DOMAIN_NAME=
HUBZILLA_DOMAIN_NAME=
OWNCLOUD_DOMAIN_NAME=
MEDIAGOBLIN_DOMAIN_NAME=
GIT_DOMAIN_NAME=
WIKI_DOMAIN_NAME=
@ -247,9 +246,6 @@ function update_domains {
if grep -q "Hubzilla domain" $COMPLETION_FILE; then
HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
fi
if grep -q "Owncloud domain" $COMPLETION_FILE; then
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
fi
if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
fi
@ -827,46 +823,80 @@ function restore_hubzilla {
fi
}
function restore_owncloud {
function restore_syncthing {
if [[ $RESTORE_APP != 'all' ]]; then
if [[ $RESTORE_APP != 'owncloud' ]]; then
if [[ $RESTORE_APP != 'syncthing' ]]; then
return
fi
fi
OWNCLOUD_PATH=/var/www/owncloud
if [ $OWNCLOUD_DOMAIN_NAME ]; then
restore_database owncloud $OWNCLOUD_DOMAIN_NAME
if [ -d $USB_MOUNT/backup/owncloudfiles ]; then
restore_directory_from_usb /root/tempowncloudfiles owncloudfiles
cp -r /root/tempowncloudfiles/* /
if [ -f /etc/systemd/system/syncthing.service ]; then
systemctl stop syncthing
systemctl stop cron
fi
if [ -d $USB_MOUNT/backup/syncthingconfig ]; then
echo $"Restoring syncthing configuration"
restore_directory_from_usb /root/tempsyncthingconfig syncthingconfig
cp -r /root/tempsyncthingconfig/* /
if [ ! "$?" = "0" ]; then
unmount_drive
exit 982
systemctl start syncthing
systemctl start cron
exit 6833
fi
rm -rf /root/tempowncloudfiles
rm -rf /root/tempsyncthingconfig
fi
if [ -d $USB_MOUNT/backup/owncloudconfig ]; then
restore_directory_from_usb /root/tempowncloudconfig owncloudconfig
cp -r /root/tempowncloudconfig/* /
if [ -d $USB_MOUNT/backup/syncthingshared ]; then
echo $"Restoring syncthing shared files"
restore_directory_from_usb /root/tempsyncthingshared syncthingshared
cp -r /root/tempsyncthingshared/* /
if [ ! "$?" = "0" ]; then
unmount_drive
exit 7825
systemctl start syncthing
systemctl start cron
exit 37904
fi
rm -rf /root/tempowncloudconfig
rm -rf /root/tempsyncthingshared
fi
# re-index the files
chown -R www-data:www-data $OWNCLOUD_PATH
chown root:root $OWNCLOUD_PATH/config/config.php
for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [ -d $USB_MOUNT/backup/syncthing ]; then
for d in $USB_MOUNT/backup/syncthing/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
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_usb /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
done
fi
if [ -f /etc/systemd/system/syncthing.service ]; then
systemctl start syncthing
systemctl start cron
fi
}
function restore_mediagoblin {
@ -1174,7 +1204,7 @@ restore_xmpp
restore_gnu_social
restore_hubzilla
restore_rss_reader
restore_owncloud
restore_syncthing
restore_mediagoblin
restore_gogs
restore_wiki

View File

@ -693,48 +693,80 @@ function restore_hubzilla {
fi
}
function restore_owncloud {
function restore_syncthing {
if [[ $RESTORE_APP != 'all' ]]; then
if [[ $RESTORE_APP != 'owncloud' ]]; then
if [[ $RESTORE_APP != 'syncthing' ]]; then
return
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
echo $"Restoring Owncloud installation"
restore_directory_from_friend /root/tempowncloudfiles owncloudfiles
cp -r /root/tempowncloudfiles/* /
if [ -f /etc/systemd/system/syncthing.service ]; then
systemctl stop syncthing
systemctl stop cron
fi
if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
echo $"Restoring syncthing configuration"
restore_directory_from_friend /root/tempsyncthingconfig syncthingconfig
cp -r /root/tempsyncthingconfig/* /
if [ ! "$?" = "0" ]; then
exit 1458
unmount_drive
systemctl start syncthing
systemctl start cron
exit 6833
fi
rm -rf /root/tempowncloudfiles
rm -rf /root/tempsyncthingconfig
fi
if [ -d $SERVER_DIRECTORY/backup/owncloudconfig ]; then
echo $"Restoring Owncloud installation"
restore_directory_from_friend /root/tempowncloudconfig owncloudconfig
cp -r /root/tempowncloudconfig/* /
if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
echo $"Restoring syncthing shared files"
restore_directory_from_friend /root/tempsyncthingshared syncthingshared
cp -r /root/tempsyncthingshared/* /
if [ ! "$?" = "0" ]; then
exit 2571
unmount_drive
systemctl start syncthing
systemctl start cron
exit 37904
fi
rm -rf /root/tempowncloudconfig
rm -rf /root/tempsyncthingshared
fi
chown -R www-data:www-data $OWNCLOUD_PATH
chown root:root $OWNCLOUD_PATH/config/config.php
# re-index files
for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
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
done
fi
if [ -f /etc/systemd/system/syncthing.service ]; then
systemctl start syncthing
systemctl start cron
fi
}
function restore_mediagoblin {
@ -1014,7 +1046,7 @@ restore_xmpp
restore_gnu_social
restore_hubzilla
restore_rss_reader
restore_owncloud
restore_syncthing
restore_mediagoblin
restore_gogs
restore_wiki