Move remote syncthing restore to app script

This commit is contained in:
Bob Mottram 2016-07-10 14:15:40 +01:00
parent f869db0ca0
commit e9ce9cc79e
2 changed files with 71 additions and 81 deletions

View File

@ -150,7 +150,77 @@ function backup_remote_syncthing {
}
function restore_remote_syncthing {
echo -n ''
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"
temp_restore_dir=/root/tempsyncthingconfig
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir syncthingconfig
cp -r $temp_restore_dir/* /
if [ ! "$?" = "0" ]; then
systemctl start syncthing
systemctl start cron
exit 6833
fi
rm -rf $temp_restore_dir
fi
if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
echo $"Restoring syncthing shared files"
temp_restore_dir=/root/tempsyncthingshared
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir syncthingshared
cp -r $temp_restore_dir/* /
if [ ! "$?" = "0" ]; then
systemctl start syncthing
systemctl start cron
exit 37904
fi
rm -rf $temp_restore_dir
fi
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
if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME
fi
echo $"Restoring syncthing files for $USERNAME"
temp_restore_dir=/root/tempsyncthing
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
systemctl start syncthing
systemctl start cron
exit 68438
fi
rm -rf $temp_restore_dir
# 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
echo $"Restore of syncthing files for $USERNAME complete"
fi
done
fi
if [ -f /etc/systemd/system/syncthing.service ]; then
systemctl start syncthing
systemctl start cron
fi
}
function remove_syncthing {

View File

@ -666,85 +666,6 @@ function restore_mailing_list {
fi
}
function restore_syncthing {
if [[ $RESTORE_APP != 'all' ]]; then
if [[ $RESTORE_APP != 'syncthing' ]]; then
return
fi
fi
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"
temp_restore_dir=/root/tempsyncthingconfig
restore_directory_from_friend $temp_restore_dir syncthingconfig
cp -r $temp_restore_dir/* /
if [ ! "$?" = "0" ]; then
unmount_drive
systemctl start syncthing
systemctl start cron
exit 6833
fi
rm -rf $temp_restore_dir
fi
if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
echo $"Restoring syncthing shared files"
temp_restore_dir=/root/tempsyncthingshared
restore_directory_from_friend $temp_restore_dir syncthingshared
cp -r $temp_restore_dir/* /
if [ ! "$?" = "0" ]; then
unmount_drive
systemctl start syncthing
systemctl start cron
exit 37904
fi
rm -rf $temp_restore_dir
fi
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
if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME
fi
echo $"Restoring syncthing files for $USERNAME"
temp_restore_dir=/root/tempsyncthing
restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
unmount_drive
systemctl start syncthing
systemctl start cron
exit 68438
fi
rm -rf $temp_restore_dir
# 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 {
if [[ $RESTORE_APP != 'all' ]]; then
if [[ $RESTORE_APP != 'mediagoblin' ]]; then
@ -1034,7 +955,6 @@ restore_personal_settings
restore_mailing_list
restore_email
restore_syncthing
restore_mediagoblin
restore_gogs
restore_wiki