Browse Source

Move remote syncthing restore to app script

Bob Mottram 8 years ago
parent
commit
e9ce9cc79e
2 changed files with 71 additions and 81 deletions
  1. 71
    1
      src/freedombone-app-syncthing
  2. 0
    80
      src/freedombone-restore-remote

+ 71
- 1
src/freedombone-app-syncthing View File

@@ -150,7 +150,77 @@ function backup_remote_syncthing {
150 150
 }
151 151
 
152 152
 function restore_remote_syncthing {
153
-	echo -n ''
153
+	if [ -f /etc/systemd/system/syncthing.service ]; then
154
+		systemctl stop syncthing
155
+		systemctl stop cron
156
+	fi
157
+
158
+	if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
159
+		echo $"Restoring syncthing configuration"
160
+		temp_restore_dir=/root/tempsyncthingconfig
161
+		function_check restore_directory_from_friend
162
+		restore_directory_from_friend $temp_restore_dir syncthingconfig
163
+		cp -r $temp_restore_dir/* /
164
+		if [ ! "$?" = "0" ]; then
165
+			systemctl start syncthing
166
+			systemctl start cron
167
+			exit 6833
168
+		fi
169
+		rm -rf $temp_restore_dir
170
+	fi
171
+
172
+	if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
173
+		echo $"Restoring syncthing shared files"
174
+		temp_restore_dir=/root/tempsyncthingshared
175
+		function_check restore_directory_from_friend
176
+		restore_directory_from_friend $temp_restore_dir syncthingshared
177
+		cp -r $temp_restore_dir/* /
178
+		if [ ! "$?" = "0" ]; then
179
+			systemctl start syncthing
180
+			systemctl start cron
181
+			exit 37904
182
+		fi
183
+		rm -rf $temp_restore_dir
184
+	fi
185
+
186
+	if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
187
+		for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
188
+			USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
189
+			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
190
+				if [ ! -d /home/$USERNAME ]; then
191
+					${PROJECT_NAME}-adduser $USERNAME
192
+				fi
193
+				echo $"Restoring syncthing files for $USERNAME"
194
+				temp_restore_dir=/root/tempsyncthing
195
+				function_check restore_directory_from_friend
196
+				restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
197
+				cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
198
+				if [ ! "$?" = "0" ]; then
199
+					rm -rf $temp_restore_dir
200
+					systemctl start syncthing
201
+					systemctl start cron
202
+					exit 68438
203
+				fi
204
+				rm -rf $temp_restore_dir
205
+
206
+				# restore device IDs from config settings
207
+				if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
208
+					cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
209
+					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
210
+				fi
211
+				if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
212
+					cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
213
+					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
214
+				fi
215
+				echo $"Restore of syncthing files for $USERNAME complete"
216
+			fi
217
+		done
218
+	fi
219
+
220
+	if [ -f /etc/systemd/system/syncthing.service ]; then
221
+		systemctl start syncthing
222
+		systemctl start cron
223
+	fi
154 224
 }
155 225
 
156 226
 function remove_syncthing {

+ 0
- 80
src/freedombone-restore-remote View File

@@ -666,85 +666,6 @@ function restore_mailing_list {
666 666
 	fi
667 667
 }
668 668
 
669
-function restore_syncthing {
670
-	if [[ $RESTORE_APP != 'all' ]]; then
671
-		if [[ $RESTORE_APP != 'syncthing' ]]; then
672
-			return
673
-		fi
674
-	fi
675
-
676
-	if [ -f /etc/systemd/system/syncthing.service ]; then
677
-		systemctl stop syncthing
678
-		systemctl stop cron
679
-	fi
680
-
681
-	if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
682
-		echo $"Restoring syncthing configuration"
683
-		temp_restore_dir=/root/tempsyncthingconfig
684
-		restore_directory_from_friend $temp_restore_dir syncthingconfig
685
-		cp -r $temp_restore_dir/* /
686
-		if [ ! "$?" = "0" ]; then
687
-			unmount_drive
688
-			systemctl start syncthing
689
-			systemctl start cron
690
-			exit 6833
691
-		fi
692
-		rm -rf $temp_restore_dir
693
-	fi
694
-
695
-	if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
696
-		echo $"Restoring syncthing shared files"
697
-		temp_restore_dir=/root/tempsyncthingshared
698
-		restore_directory_from_friend $temp_restore_dir syncthingshared
699
-		cp -r $temp_restore_dir/* /
700
-		if [ ! "$?" = "0" ]; then
701
-			unmount_drive
702
-			systemctl start syncthing
703
-			systemctl start cron
704
-			exit 37904
705
-		fi
706
-		rm -rf $temp_restore_dir
707
-	fi
708
-
709
-	if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
710
-		for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
711
-			USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
712
-			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
713
-				if [ ! -d /home/$USERNAME ]; then
714
-					${PROJECT_NAME}-adduser $USERNAME
715
-				fi
716
-				echo $"Restoring syncthing files for $USERNAME"
717
-				temp_restore_dir=/root/tempsyncthing
718
-				restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
719
-				cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
720
-				if [ ! "$?" = "0" ]; then
721
-					rm -rf $temp_restore_dir
722
-					unmount_drive
723
-					systemctl start syncthing
724
-					systemctl start cron
725
-					exit 68438
726
-				fi
727
-				rm -rf $temp_restore_dir
728
-
729
-				# restore device IDs from config settings
730
-				if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
731
-					cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
732
-					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
733
-				fi
734
-				if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
735
-					cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
736
-					chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
737
-				fi
738
-			fi
739
-		done
740
-	fi
741
-
742
-	if [ -f /etc/systemd/system/syncthing.service ]; then
743
-		systemctl start syncthing
744
-		systemctl start cron
745
-	fi
746
-}
747
-
748 669
 function restore_mediagoblin {
749 670
 	if [[ $RESTORE_APP != 'all' ]]; then
750 671
 		if [[ $RESTORE_APP != 'mediagoblin' ]]; then
@@ -1034,7 +955,6 @@ restore_personal_settings
1034 955
 restore_mailing_list
1035 956
 restore_email
1036 957
 
1037
-restore_syncthing
1038 958
 restore_mediagoblin
1039 959
 restore_gogs
1040 960
 restore_wiki