@@ -127,18 +127,13 @@ if [ -r "$1" ] ; then
127
127
echo -e $PNAME : " The backup source (candidate) exists!"
128
128
fi
129
129
DEST_TEST=" ${1/ $FB / } "
130
- if [[ $DRYRUN = false && " $DEST_TEST " = " $1 " ]] ; then
131
- echo -e $PNAME : " The backup source to restore are not allowed to be outside " $FB " .\nTerminating..."
132
- exit 2
133
- else
134
- HAVING_ERRORS=true
130
+ if [[ " $DEST_TEST " = " $1 " ]] ; then
131
+ echo -e $PNAME : " The backup source to restore are not allowed to be outside " $FB " .\nTerminating..."
132
+ exit 2
135
133
fi
136
- elif [ $DRYRUN = false ] ; then
134
+ else
137
135
echo -e $PNAME : " The backup source \" $1 \" doesn't exist!\nTerminating..."
138
136
exit 2
139
- else
140
- echo -e $PNAME : " The backup source \" $1 \" doesn't exist!"
141
- HAVING_ERRORS=true
142
137
fi
143
138
144
139
# We need to sort out which backup to restore.
@@ -205,7 +200,7 @@ if [ "$BACKUP_SOURCE_TYPE" = "folder" ] ; then
205
200
fi
206
201
else
207
202
BACKUP_SOURCE=" ${BACKUP_CANDIDATE[0]} "
208
- if [ $DEBUG -eq 0 ] ; then
203
+ if [ $DEBUG -eq || $VERBOSE = true ] ; then
209
204
echo -e $PNAME : " We found the latest file within the folder:\n$BACKUP_SOURCE "
210
205
fi
211
206
fi
216
211
217
212
# Preparing the folder name we shall append, or not.
218
213
FOLDER_BASE_NAME=" ${BACKUP_SOURCE##*/ } "
219
- FOLDER_STEM_NAME=" ${FOLDER_BASE_NAME%% .* } "
214
+ if [[ $VERBOSE = true || $DEBUG -eq 0 ]] ; then
215
+ echo -e $PNAME : " The folder base name we will use for basis for the the tar-dump in is:\n$FOLDER_BASE_NAME "
216
+ fi
217
+ FOLDER_STEM_NAME=" $( baseNameFromBackupFile \" $FOLDER_BASE_NAME \" ) "
218
+ # FOLDER_STEM_NAME="${FOLDER_BASE_NAME%%.*}"
220
219
221
220
if [[ $VERBOSE = true || $DEBUG -eq 0 ]] ; then
222
221
echo -e $PNAME : " The folder stem name we will use for storing the tar-dump in is:\n$FOLDER_STEM_NAME "
@@ -246,7 +245,7 @@ if [ "$PROBE" = "$DEST_FOLDER" ] ; then
246
245
if [ $DRYRUN = false ] ; then
247
246
if [ ! -d " $DEST_FOLDER " ] ; then
248
247
if [[ $VERBOSE = true || $DEBUG -eq 0 ]] ; then
249
- echo " $PNAME : " $DEST_FOLDER " didn't exist: mkdir -p " $DEST_FOLDER " ."
248
+ echo " $PNAME : $DEST_FOLDER didn't exist: mkdir -p $DEST_FOLDER ."
250
249
fi
251
250
mkdir -p " $DEST_FOLDER "
252
251
MADE_FOLDER=true
@@ -263,11 +262,11 @@ if [ "$PROBE" = "$DEST_FOLDER" ] ; then
263
262
# NO: because we-re not really making a restore when dryrun is on,
264
263
# we do restore to a temp folder that we subsequently delete.
265
264
if [ ! -d " $DEST_FOLDER " ] ; then
266
- echo $PNAME : Making destination folder: mkdir -p " $DEST_FOLDER "
267
- else
268
- echo " $PNAME : " $DEST_FOLDER " already exist and --force isn't used : bailing out"
269
- ls -ld " $DEST_FOLDER "
270
- exit 2
265
+ echo " $PNAME : WOULD have made destination folder: mkdir -p $DEST_FOLDER "
266
+ else
267
+ echo " $PNAME : $DEST_FOLDER already exist and --force isn't used : bailing out"
268
+ ls -ld " $DEST_FOLDER "
269
+ exit 2
271
270
fi
272
271
fi
273
272
else
318
317
fi
319
318
320
319
321
- exit_status =0
320
+ EXIT_STATUS =0
322
321
if [ $DRYRUN = true ] ; then
323
322
trap " ctrl_c" INT
324
323
@@ -327,9 +326,8 @@ ctrl_c() {
327
326
echo " $PNAME : We: rm -fr $DRY_RUN_FOLDER ."
328
327
rm -fr $DRY_RUN_FOLDER
329
328
}
330
- if [ $HAVING_ERRORS = false ] ; then
331
- DRY_RUN_FOLDER=$( mktemp -d " /tmp/OneShot.restore.sh.XXX" )
332
- sudo tar -x -z $VERBOSE_OPTIONS -f " $BACKUP_SOURCE " -C $DRY_RUN_FOLDER
329
+ if [ $HAVING_ERRORS = false ] ; then DRY_RUN_FOLDER=$( mktemp -d " /tmp/OneShot.restore.sh.XXX" )
330
+ sudo tar -x -z $VERBOSE_OPTIONS -f " $BACKUP_SOURCE " -C " $DRY_RUN_FOLDER "
333
331
if [ $? -lt 130 ] ; then
334
332
rm -fr $DRY_RUN_FOLDER
335
333
fi
@@ -338,8 +336,10 @@ ctrl_c() {
338
336
echo -e " $PNAME : tar -x -z $VERBOSE_OPTIONS -f \" $BACKUP_SOURCE \" -C $DRY_RUN_FOLDER "
339
337
echo -e " $PNAME : rm -fr $DRY_RUN_FOLDER "
340
338
fi
339
+
341
340
else
342
- trap " ctrl_c" INT
341
+
342
+ trap " ctrl_c" INT
343
343
344
344
ctrl_c () {
345
345
if [[ $VERBOSE = true || $DEBUG -eq 0 ]] ; then
@@ -350,20 +350,28 @@ ctrl_c() {
350
350
rm -fr $DEST_FOLDER
351
351
fi
352
352
}
353
+
354
+ if [[ $VERBOSE = true || $DEBUG -eq 0 ]] ; then
355
+ echo -e " $PNAME : sudo tar -x -z $VERBOSE_OPTIONS -f $BACKUP_SOURCE -C $DEST_FOLDER "
356
+ fi
353
357
sudo tar -x -z $VERBOSE_OPTIONS -f " $BACKUP_SOURCE " -C " $DEST_FOLDER "
354
- exit_status=$?
355
- fi
356
- if [ $exit_status -eq 0 ] ; then
357
- echo " (" $DEST_FOLDER " )"
358
- # This only looks like this here, not when the script is implicitly
359
- # initiated from a daemon.
360
- elif [ $exit_status -eq 1 ] ; then
361
- echo " $PNAME : Contents of " $DEST_FOLDER " ."
362
- ls -l " $DEST_FOLDER "
363
- echo " $PNAME : Contents of " $DEST_FOLDER " ."
364
- elif [ $exit_status -ne 130 ] ; then
365
- if [[ $MADE_FOLDER = true || $WITHIN_TMP = true ]] ; then
366
- rm -fr $DEST_FOLDER
358
+ EXIT_STATUS=$?
359
+ # | journalThis 7 OneShot
360
+
361
+ if [ $EXIT_STATUS -gt 1 ] ; then
362
+ if [[ $VERBOSE = true || $DEBUG -eq 0 ]] ; then
363
+ echo " $PNAME : exit status after tar commmand (fatal error) = $EXIT_STATUS "
364
+ fi
365
+
366
+ if [ $EXIT_STATUS -ne 130 ] ; then
367
+ if [[ $MADE_FOLDER = true || $WITHIN_TMP = true ]] ; then
368
+ rm -fr $DEST_FOLDER
369
+ fi
370
+ fi
371
+ elif [ $EXIT_STATUS -eq 0 ] ; then
372
+ echo -e " \n(" $DEST_FOLDER " )\n"
373
+ # This only looks like this here, not when the script is implicitly
374
+ # initiated from a daemon.
367
375
fi
368
376
fi
369
- exit $exit_status
377
+ exit $EXIT_STATUS
0 commit comments