-
Notifications
You must be signed in to change notification settings - Fork 0
/
Devices__BackupPartitionTable_GPT.sh
83 lines (67 loc) · 2 KB
/
Devices__BackupPartitionTable_GPT.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
#!/bin/sh
TARGET="/DB001_F7/00___GPT_Backup"
if [ ! -d "${TARGET}" ]
then
mkdir "${TARGET}"
fi
cd ${TARGET}
if [ $? -ne 0 ]
then
echo "\n\t Failed to set "${TARGET}" as working directory for GPT image backup. Unable to proceed.\n Bye!\n" ; exit 1
fi
echo "\n WORKING DIRECTORY ==> `pwd`"
dRoot=`df / | grep '^/dev' | awk '{ print $1 }' | cut -c1-8 `
for DISK in 1 2 3 4 5 6
do
LABEL="DB00${DISK}"
dDat=`ls -l "/dev/disk/by-label/${LABEL}_F1" 2>>/dev/null | grep '/dev' | awk '{ print $11 }' `
echo ${dDat}
if [ -n "${dDat}" ]
then
testorD=`echo "${dDat}" | cut -f3 -d/ `
echo "testorD= ${testorD}"
dUUID=`ls -l /dev/disk/by-uuid | grep ${testorD} | awk '{ print $9 }' `
echo "dUUID= ${dUUID}"
testor=`grep "${dUUID}" /etc/fstab | grep -v '^#' `
echo "testor= ${testor}"
if [ -n "${testor}" ]
then
dDevP="/dev/${testorD}"
echo dDepP= ${dDevP}
dMount=`df ${dDevP} | grep '/dev' | awk '{ print $6 }' `
echo dMount= ${dMount}
if [ "${dMount}" = "/" ]
then
dDev=`echo "${dDevP}" | cut -c1-8 `
else
dDev=`echo "${dDevP}" | cut -c1-8 | grep -v ${dRoot} `
fi
echo "dDev= ${dDev}"
if [ -n "${dDev}" ]
then
BackFile="GTP_Backup__${LABEL}${DATE}"
echo "\n Creating backup of GPT Partition Table for disk ${LABEL} [${dDev}] ..."
if [ -s ./sgdisk ]
then
rm -fv ./sgdisk
fi
COM="sgdisk --backup='${BackFile}' '${dDev}'"
echo "\n\t COMMAND: ${COM} ..."
eval ${COM} 2>&1 | awk '{ printf("\t\t %s\n", $0 ) ; }'
echo "\t\t ==> RC = $?"
if [ -s ./sgdisk ]
then
rm -fv ./sgdisk
fi
ls -ltr 2>&1 | awk '{ printf("\t\t %s\n", $0 ) ; }'
echo "\n\t To restore the GPT Partition Table to original values, use the command:\n\t\t ==> sgdisk --load-backup='${BackFile}' '${dDev}'\n"
else
echo "\n Disk ${LABEL}_F1 is currently offline ...\n"
fi
else
echo "\n ${LABEL}_F1 is not recognized as a disk! No definition registered in '/etc/fstab' ...\n"
fi
else
echo "\n Disk ${LABEL}_F1 is not registered as a DBUS device! ...\n"
fi
done