-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackupSD.sh
266 lines (233 loc) · 10.1 KB
/
backupSD.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
# ******************************************************************************
# *
# * Copyright (c) 2021 Phoenix Contact GmbH & Co. KG. All rights reserved.
# * Licensed under the MIT. See LICENSE file in the project root for full license information.
# *
# ******************************************************************************
CURRENT=$(pwd)
DATAPATH="$1"
StoreBackupAt="$2"
if [[ $DATAPATH == "" && $StoreBackupAt == "" ]]; then
echo "Usage: ./backupSD.sh DATAPATH StoreBackupAt";
echo "Example: ./backupSD.sh /media/rfs/rw/ /media/rfs/rw/";
exit 255;
fi
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
## Set the directories for the backup
. ${SCRIPT_DIR}/../Backup/backupSettings.sh
df -ha | grep rfs
${SCRIPT_DIR}/../Diagnostic/checkActivePartition.sh
if [ "$(whoami)" != "root" ]; then
echo "please use ROOT to create a backup";
exit 255;
fi
echo 'Choose the kind of Backup you want to create.'
PS3="Select your choice: "
options=("Upperdir" \
"PCWE Project only" \
"Directories specified by backupSettings.sh" \
"Continue" \
"Exit")
select opt in "${options[@]}"
do
case $opt in
"Upperdir")
STORE="Upperdir"
echo "STORE = $STORE"
;;
"PCWE Project only")
STORE="PCWE"
echo "STORE = $STORE"
;;
"Directories specified by backupSettings.sh")
echo "check 'backupSettings.sh' to check or change settings"
(set -o posix ; set) | grep STORE | grep true
STORE="Changes"
echo "STORE = $STORE"
;;
# "Everything")
# STORE="Everything"
# echo "STORE = $STORE"
# ;;
# "Containers")
# STORE="Everything"
# echo "STORE = $STORE"
# ;;
"Continue")
if [ "$STORE" == "" ]; then
echo "STORE = $STORE empty Exit Script"
exit 1
fi
break
;;
"Exit")
exit 1
break
;;
*) echo "invalid option $REPLY";;
esac
done
echo 'Do you wish to add stored licenses and PLC device data to this backup?'
PS3="Select your choice: "
options=("Don't Store Licence" "Store Licence" "Don't Store DeviceData" "Store DeviceData" "Continue" "Exit")
select opt in "${options[@]}"
do
case $opt in
"Don't Store Licence")
STORE_LICENCE=false
echo "STORE_LICENCE = $STORE_LICENCE"
;;
"Store Licence")
STORE_LICENCE=true
echo "STORE_LICENCE = $STORE_LICENCE"
;;
"Don't Store DeviceData")
STORE_DEVICEDATA=false
echo "STORE_DEVICEDATA = $STORE_DEVICEDATA"
;;
"Store DeviceData")
STORE_DEVICEDATA=true
echo "STORE_DEVICEDATA = $STORE_DEVICEDATA"
;;
"Continue")
if [ "$STORE_LICENCE" == "" ]; then
echo "STORE_LICENCE = $STORE_LICENCE empty. Exit Script."
exit 1
fi
if [ "$STORE_DEVICEDATA" == "" ]; then
echo "STORE_DEVICEDATA = $STORE_DEVICEDATA empty. Exit Script."
exit 1
fi
break
;;
"Exit")
exit 1
break
;;
*) echo "invalid option $REPLY";;
esac
done
echo "Please check if the paths are correct."
echo "DataPath: '$DATAPATH' The directory you want to backup."
echo "StoreBackupAt: '$StoreBackupAt' the location you want to store your backup at."
echo "Storage Mode: '$STORE' is activated."
echo ":"
read -r -p "Are you sure? [y/N] all settings are correct
" response
###
### Storage Function
###
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
DATE=$(date -I)
date > ${StoreBackupAt}/DATEFILE;
tar -cvpf ${StoreBackupAt}/backup-${DATE}.tar -C ${StoreBackupAt} DATEFILE
echo "STORE = $STORE"
case "$STORE" in
"Upperdir")
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} upperdir && echo "Done"
;;
"Changes")
echo -e "Store specified folders only:"
(set -o posix ; set) | grep "STORE" | grep "true"
read -r -p "Proceed creating backup [y/N] : " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
## Add Folders to Tar.
if $STORE_UNIX_PASSWORD_CHANGES; then
echo "Storing UNIX_PASSWORD_CHANGES"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${UNIX_PASSWORD_Changes[@]} && echo "Done"
fi
if $STORE_NETWORK; then
echo "Storing Network Settings"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${NETWORK} && echo "Done"
fi
if $STORE_SSH_KEYs; then
echo "Storing SSH Keys"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${SSH_KEYs} && echo "Done"
fi
if $STORE_PLCnext_PROJECTS; then
echo "Storing PROJECTS"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${PROJECTS} && echo "Done"
fi
if $STORE_PLCnext_SYSTEM_UM; then
echo "Storing SYSTEM UM Settings"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${PLCnext_UM}&& echo "Done"
fi
if $STORE_PLCnext_SYSTEM_SCM; then
echo "Storing SYSTEM SCM Settings"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${PLCnext_SCM} && echo "Done"
fi
if $STORE_PLCNext_SERVICES; then
echo "Storing SERVICE Settings"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${SERVICES} && echo "Done"
### If required add keys for specific services
#STORE_PLCNext_SERVICES_Ehmi
#STORE_PLCNext_SERVICES_Grpc
#STORE_PLCNext_SERVICES_LinuxSyslog
#STORE_PLCNext_SERVICES_OpcUA
#STORE_PLCNext_SERVICES_PLCnextStore
#STORE_PLCNext_SERVICES_PortAuthentication
#STORE_PLCNext_SERVICES_Spm
#STORE_PLCNext_SERVICES_SpnsProxy
#STORE_PLCNext_SERVICES_Syslog
#STORE_PLCNext_SERVICES_Wcm
fi
if $STORE_PLCnext_SECURITY; then
echo "Storing PLCnext_SECURITY directory"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${PLCnext_SECURITY} && echo "Done"
fi
if $STORE_INSTALLED_APPS; then
echo "Storing INSTALLED_APPS"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${INSTALLED_APPS} && echo "Done"
fi
if $STORE_ALL_CONFIG; then
echo "Storing CONFIG directory"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${CONFIG} && echo "Done"
fi
if $STORE_ALL_DATA; then
echo "Storing DATA directory"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${DATA} && echo "Done"
fi
fi
;;
"PCWE")
echo "Storing PCWE directory"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${PROJECTS} && echo "Done"
;;
esac
fi
if $STORE_DEVICEDATA; then
echo "WATCH OUT!
Stored DeviceData are bound to the Hardware of the PLC do not use this backup for another PLC!"
echo "Storing DEVICEDATA"
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C "/etc" ${DEVICEDATA} && echo "Done"
fi
if $STORE_LICENCE; then
echo "WATCH OUT!
Stored Licenses are bound to the Hardware ID do not use this backup for another PLC / SD"
echo "WATCH OUT!
SD License is bound to this SD card do not use backup for another SD."
read -r -p "Realy add License? [y/N]
" response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
echo "Adding Licence, remember to unzip with caution!"
echo "Restoring this backup might void an SD-Cards License if overwritten."
tar -rpf ${StoreBackupAt}/backup-${DATE}.tar -C ${DATAPATH} ${INSTALLED_LICENSE_FILES} && echo "Done"
else
echo "Storing licence has been skipped"
fi
fi
if [ -f "${StoreBackupAt}/backup-${DATE}.tar" ]; then
chown admin:plcnext ${StoreBackupAt}/backup-*.tar
echo "Contents of Backup:"
tar -tvf "${StoreBackupAt}/backup-${DATE}.tar" | grep "/$"
echo "How to restore:
./restoreBackup.sh /media/rfs/rw/ /media/rfs/rw/backup-${DATE}.tar
"
else
echo "No backup created please fix your input data."
exit 1
fi