-
Notifications
You must be signed in to change notification settings - Fork 0
/
fnc_sort-list.sh
279 lines (168 loc) · 7.07 KB
/
fnc_sort-list.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
267
268
269
270
271
272
273
274
275
276
do_sort_list() {
printf "\n--------------------------------------( do_sort_list )------------------------------------------\n" 1>&5
# dataset sort
do_declare_arrays
if [ -z "$s_sets" ] ;then
lsets="$s_pool"
else
for set in $s_sets ;do #(!double quoting expands as single word)
lsets+="$s_pool/$set "
#lsets="$lsets $s_pool/$set"
done
fi
include_array+=($s_pool)
parent_array+=($s_pool)
include_Array+=([$s_pool]=p)
[ "$strip_pool" = 1 ] && dest_Array+=([$s_pool]="$d_path")
[ "$strip_pool" != 1 ] && dest_Array+=([$s_pool]="$d_path/$s_pool")
for lset in $lsets ; do
for src_child in $($s_zfs list -Hr -o name $lset) ;do
[ "$src_child" = "$s_pool" ] && continue
[ "$strip_pool" = 1 ] && dest_child="$d_path/${src_child#${s_pool}/}"
[ "$strip_pool" != 1 ] && dest_child="$d_path/$src_child"
local incl="$($s_zfs get -s local,received -H -o value $pfix:incl $src_child)"
local excl="$($s_zfs get -s local,inherited,received -H -o value $pfix:excl $src_child)"
local orig="$($s_zfs get -t filesystem,volume -H -o value origin $src_child)"
[ "$src_child" = "$lset" ] && [ -z "$incl" ] && incl=$set_type
[ "$set_recurse" = 0 ] && [ -z "$incl" ] && excl=1
if [ "$excl" = "1" ] ;then
exclude_array+=($src_child)
#echo "[SORT] classified as excluded ($src_child)"
elif [ "$incl" = "p" ] ;then
include_array+=($src_child)
parent_array+=($src_child)
include_Array+=([$src_child]=p)
dest_Array+=([$src_child]="$dest_child")
#echo "[SORT] classified as parent ($src_child)"
elif [ "$incl" = "c" ] ;then
include_array+=($src_child)
container_array+=($src_child)
include_Array+=([$src_child]=c)
dest_Array+=([$src_child]="$dest_child")
#echo "[SORT] classified as container ($src_child)"
else
include_array+=($src_child)
dataset_array+=($src_child)
[ "$orig" = "-" ] && include_Array+=([$src_child]=d)
[ "$orig" = "-" ] || include_Array+=([$src_child]=cl)
[ "$orig" = "-" ] || temp_clone_array+=($src_child)
[ "$orig" = "-" ] || temp_clone_Array+=([$src_child]="$orig")
dest_Array+=([$src_child]="$dest_child")
#echo "[SORT] classified as else-dataset ($src_child)"
fi
done
done
do_clone_array_sort
do_verblist
}
do_clone_array_sort () {
printf "\n--------------------------------------( do_clone_array_sort )-----------------------------------\n" 1>&5
# re-sorting of clone arrays for correct order in clone of clone situations
declare -a sort_clone_array
local clone
for clone in "${temp_clone_array[@]}" ;do
unset origin_clone_check
until [ "$origin_clone_check" = end ] ;do
local origin_set="${temp_clone_Array["${clone:-null}"]%@*}"
local origin_clone_check="${temp_clone_Array["${origin_set:-null}"]:-end}"
if [ "$origin_clone_check" != end ] ;then
sort_clone_array+=($clone)
clone=$origin_set
else
sort_clone_array+=($clone)
fi
done
done
unset clone #just in case
for ((i=${#sort_clone_array[@]}-1; i>=0; i--)) ;do
clone="${sort_clone_array[$i]}"
[ "${clone_Array["$clone"]}" ] && continue
clone_array+=($clone)
clone_Array+=([$clone]=${temp_clone_Array[$clone]})
done
unset temp_clone_array
unset temp_clone_Array
unset sort_clone_array
}
do_verblist () {
[ "$verblist" = 1 ] && do_print_include_array
[ "$verb_incl" = 1 ] && do_print_include_Array
[ "$verb_dest" = 1 ] && do_print_dest_Array
[ "$verb_clone" = 1 ] && do_print_clone_Array
}
do_print_temp_clone_arrays () {
printf "\n--------------------------------------( do_print_temp_clone_arrays )----------------------------\n" 1>&3
printf "[LIST01] %20s\n" "temp_clone_array :" 1>&3
printf "[LIST01] %s\n" "${temp_clone_array[@]}" 1>&3
printf '[LIST01] %20s\n' "temp_clone_Array :" 1>&3
for i in ${!temp_clone_Array[@]} ;do
printf '[LIST01] %20s %s\n' "clone < =" "$i" 1>&3
printf '[LIST01] %20s %s\n' "origin > =" "${temp_clone_Array[$i]}" 1>&3
done
echo "------------------------------------------------------------------------------------------------" 1>&3
}
do_print_sort_clone_array () {
printf "\n--------------------------------------( do_print_sort_clone_array )---------------------------\n" 1>&3
printf "[LIST02] %20s\n" "sort_clone_array :" 1>&3
printf "[LIST02] %s\n" "${sort_clone_array[@]}" 1>&3
echo "------------------------------------------------------------------------------------------------" 1>&3
}
do_print_include_array () {
printf "\n--------------------------------------( do_print_include_array )--------------------------------\n" 1>&3
#sleep 0.1 # to sync logging
printf '[LIST1] %20s\n' "include_array :" 1>&3
printf '[LIST1] %s\n' "${include_array[@]}" 1>&3
printf "[LIST1] %20s\n" 'parent_array :' 1>&3
printf "[LIST1] %s\n" "${parent_array[@]}" 1>&3
printf "[LIST1] %20s\n" 'container_array :' 1>&3
printf "[LIST1] %s\n" "${container_array[@]}" 1>&3
printf "[LIST1] %20s\n" "dataset_array :" 1>&3
printf "[LIST1] %s\n" "${dataset_array[@]}" 1>&3
printf "[LIST1] %20s\n" "clone_array :" 1>&3
printf "[LIST1] %s\n" "${clone_array[@]}" 1>&3
printf "[LIST1] %20s\n" 'exclude_array :' 1>&3
printf "[LIST1] %s\n" "${exclude_array[@]}" 1>&3
echo "------------------------------------------------------------------------------------------------" 1>&3
}
do_print_include_Array () {
printf "\n--------------------------------------( do_print_include_Array )------------------------------\n" 1>&3
#sleep 0.1 # to sync logging
printf '[LIST2] %20s\n' "include_Array :" 1>&3
for i in ${!include_Array[@]} ;do
printf '[LIST2] %18s = %s\n' "${include_Array[$i]}" "$i" 1>&3
done
echo "------------------------------------------------------------------------------------------------" 1>&3
}
do_print_dest_Array () {
printf "\n--------------------------------------( do_print_dest_Array )---------------------------------\n" 1>&3
#sleep 0.1 # to sync logging
printf '[LIST3] %20s\n' "dest_Array :" 1>&3
for i in ${!dest_Array[@]} ;do
printf '[LIST3] %18s = %s\n' "src <" "$i" 1>&3
printf '[LIST3] %18s = %s\n' "dest >" "${dest_Array[$i]}" 1>&3
done
echo "------------------------------------------------------------------------------------------------" 1>&3
}
do_print_clone_Array () {
printf "\n--------------------------------------( do_print_clone_Array )--------------------------------\n" 1>&3
#sleep 0.1 # to sync logging
printf '[LIST4] %20s\n' "clone_Array :" 1>&3
for i in ${!clone_Array[@]} ;do
printf '[LIST4] %20s %s\n' "clone < =" "$i" 1>&3
printf '[LIST4] %20s %s\n' "origin > =" "${clone_Array[$i]}" 1>&3
done
echo "------------------------------------------------------------------------------------------------" 1>&3
}
do_declare_arrays () {
declare -ag include_array
declare -ag parent_array
declare -ag container_array
declare -ag dataset_array
declare -ag exclude_array
declare -ag temp_clone_array
declare -ag clone_array
declare -Ag include_Array
declare -Ag dest_Array
declare -Ag temp_clone_Array
declare -Ag clone_Array
}