Checking for orphaned files should be redundant now, that code has been removed
This commit is contained in:
parent
2f89821404
commit
88b5a4ca2e
183
qq2clone
183
qq2clone
|
@ -1502,186 +1502,6 @@ for id in "${!BAD_CL[@]}"; do
|
|||
echo
|
||||
done
|
||||
return 0
|
||||
}
|
||||
#=========================================================================#
|
||||
prompt_delete_orphans ()
|
||||
# DESCRIPTION: Find any image files in qq2clone's default storage directory
|
||||
# that don't belong to qqclone2 or any machine on the current libvirt
|
||||
# connetion
|
||||
# INPUT: None
|
||||
# OUTPUT: Prompts user and gives status updates
|
||||
# PARAMETERS: None
|
||||
#=========================================================================#
|
||||
{
|
||||
# This function is very long, partially due to lots of echo statements
|
||||
# and requests for user input. However, all of the text describing things
|
||||
# to the user also makes it easy to understand the code, so for now
|
||||
# I am leaving it as-is.
|
||||
hr
|
||||
echo
|
||||
echo "qq2clone will look in its default storage pool:"
|
||||
echo
|
||||
echo " ${OPT[STORAGE]}"
|
||||
echo
|
||||
echo "Any files found there that are not storage devices in use by"
|
||||
echo "a virtual machine on the current libvirt connection or qq2clone"
|
||||
echo "templates will be considered orphans. This shouldn't take too long,"
|
||||
echo "but it could if you have a lot of files in that location, a large"
|
||||
echo "number of domains defined, or a slow machine"
|
||||
echo
|
||||
echo "qq2clone will take no action on these files unless directed to"
|
||||
echo
|
||||
echo "Ctrl+C to abort search"
|
||||
echo
|
||||
hr
|
||||
echo
|
||||
local patt
|
||||
patt="^[[:space:]]*[^[:space:]]+[[:space:]]+([^[:space:]].*[^[:space:]])"
|
||||
patt="${patt}[[:space:]]*$"
|
||||
|
||||
local check
|
||||
check="$(virsh list --all)"
|
||||
check="$(strip_ws "$check")"
|
||||
if [[ -n "$check" ]]; then check=1; else check=0; fi
|
||||
|
||||
local uuid device path c=8 n match
|
||||
|
||||
echo "Generating list of domain storage devices..."
|
||||
while (( check )) && read -r device; do
|
||||
while (( c )); do (( c-- )); continue 2; done;
|
||||
|
||||
if [[ -z "$device" ]]; then
|
||||
for ((c=3;c>0;)); do
|
||||
read -r n; [[ -z "$n" ]] && continue
|
||||
(( c-- ))
|
||||
done
|
||||
continue
|
||||
fi
|
||||
[[ "$device" =~ $patt ]] && write_pipe 0 "${BASH_REMATCH[1]}"
|
||||
|
||||
done < <( while read -r uuid; do \
|
||||
echo "domblklist $uuid; echo --err null;\
|
||||
domblklist $uuid --inactive;"; done \
|
||||
< <( virsh list --all --uuid ) | virsh 2>&1 )
|
||||
|
||||
# ^ less complicated version of the same hack in load_template, will also
|
||||
# be replaced
|
||||
|
||||
# We have all the disk files associated with domains, but we still need
|
||||
# the ones referenced by template XML
|
||||
declare -a templates
|
||||
while read -r line; do
|
||||
write_pipe 0 "$line"
|
||||
done < <(sqlite3 "select disks from TEMPLATES;")
|
||||
|
||||
echo "Generating list of filepaths in default storage pool..."
|
||||
declare -a f_paths
|
||||
local path
|
||||
while read -r path; do
|
||||
f_paths[${#f_paths[@]}]="$path"
|
||||
done < <(find "${OPT[STORAGE]}" -depth -mindepth 1 2>/dev/null)
|
||||
|
||||
echo "Comparing..."
|
||||
declare -a orphans
|
||||
match=0
|
||||
for path in "${f_paths[@]}"; do
|
||||
while read -r device; do
|
||||
(( match )) && continue
|
||||
if [[ "$device" == "$path" ]]; then
|
||||
match=1
|
||||
fi
|
||||
done < <( read_pipe 1 )
|
||||
[[ "$match" == "1" ]] && { match=0; continue; }
|
||||
orphans[${#orphans[@]}]="$path"
|
||||
done
|
||||
read_pipe >/dev/null
|
||||
|
||||
local j=${#orphans[@]}
|
||||
if ((j)); then
|
||||
echo
|
||||
echo "Total potentially orphaned files: $j"
|
||||
echo
|
||||
echo "Remember that false positives are very possible. qq2clone"
|
||||
echo "considers any file in its default storage pool that is not"
|
||||
echo "a storage device for a virtual machine listed by virsh or"
|
||||
echo "a template known to qq2clone to be an orphan. It is unwise to"
|
||||
echo "delete any detected files without looking at them first"
|
||||
echo
|
||||
prompt_yes_no && less \
|
||||
< <( for path in "${orphans[@]}"; do echo "$path"; done )
|
||||
echo
|
||||
echo "Would you like to store a copy of this list to disk?"
|
||||
local temp
|
||||
if prompt_yes_no; then
|
||||
temp="$(mktemp)"
|
||||
for path in "${orphans[@]}"; do echo "$path"; done > "$temp"
|
||||
echo "File printed to $temp"
|
||||
fi
|
||||
echo
|
||||
echo "1) Delete all files found"
|
||||
echo "2) Answer a prompt to delete or leave alone each file"
|
||||
echo "3) Abort and handle the situation manually"
|
||||
local select prompt=1 file fail=0
|
||||
select="$(prompt_num 1 3)"
|
||||
((select==1)) && prompt=0
|
||||
((select==3)) && { echo "Abort"; return 0; }
|
||||
|
||||
local i
|
||||
for ((i=0;i<j;i++));do
|
||||
hr
|
||||
file="${orphans["$i"]}"
|
||||
echo "$file"
|
||||
echo " $((i+1))/$j"
|
||||
echo " Type: $(file "$file")"
|
||||
if ((prompt)); then
|
||||
echo " 1) Delete it"
|
||||
echo " 2) Leave it alone"
|
||||
echo " 3) Delete all"
|
||||
echo " 4) Abort"
|
||||
select="$(prompt_num 1 4)"
|
||||
((select==2)) && continue
|
||||
((select==3)) && prompt=0
|
||||
((select==4)) && { echo "Abort"; return 0; }
|
||||
fi
|
||||
chmod +rw "$file" &>/dev/null
|
||||
rmdir "$file" &>/dev/null
|
||||
rm -f "$file" &>/dev/null
|
||||
if [[ -e "$file" ]]; then
|
||||
echo "Unable to delete"
|
||||
write_pipe "$file"
|
||||
fail=1
|
||||
else
|
||||
echo "Deleted"
|
||||
fi
|
||||
echo
|
||||
done
|
||||
if ((fail)); then
|
||||
echo "Check complete, but failed to delete some files."
|
||||
echo
|
||||
echo "View a list of fails qq2clone failed to delete?"
|
||||
if prompt_yes_no; then
|
||||
echo
|
||||
read_pipe 1 | less
|
||||
else
|
||||
echo
|
||||
fi
|
||||
echo "Save to disk?"
|
||||
if prompt_yes_no; then
|
||||
echo
|
||||
temp="$(mktemp)"
|
||||
read_pipe > "$temp"
|
||||
echo "File printed to $temp"
|
||||
else
|
||||
echo
|
||||
fi
|
||||
else
|
||||
echo "Orphaned file check completed"
|
||||
fi
|
||||
else
|
||||
echo
|
||||
echo "No orphaned files were found"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
#-----------------------------#
|
||||
|
@ -2611,9 +2431,6 @@ for t in "${templates[@]}"; do
|
|||
echo
|
||||
done
|
||||
|
||||
echo "Do a complete check for potentially orphaned images files now?"
|
||||
prompt_yes_no && { echo; prompt_delete_orphans; }
|
||||
|
||||
exit 0
|
||||
}
|
||||
#=========================================================================#
|
||||
|
|
Loading…
Reference in New Issue