5 # IMPORTANT: affects order produced by 'sort' and 'ceph-diff-sorted'
6 # relies on this ordering
10 temp_file
=/tmp
/temp.$$
11 timestamp
=$
(date -u +%Y
%m
%d
%k
%M
)
12 lspools_err
="${out_dir}/lspools-${timestamp}.error"
13 rados_out
="${out_dir}/rados-${timestamp}.intermediate"
14 rados_err
="${out_dir}/rados-${timestamp}.error"
15 rgwadmin_out
="${out_dir}/radosgw-admin-${timestamp}.intermediate"
16 rgwadmin_err
="${out_dir}/radosgw-admin-${timestamp}.error"
17 delta_out
="${out_dir}/orphan-list-${timestamp}.out"
20 echo "An error was encountered while running '$1'. Aborting."
22 echo "Review file '$2' for details."
25 echo "*** WARNING: The results are incomplete. Do not use! ***"
31 echo "Available pools:"
32 rados lspools
>"$temp_file" 2>"$lspools_err"
33 if [ "$?" -ne 0 ] ;then
34 error_out
"rados lspools" "$lspools_err"
36 sed 's/^/ /' $temp_file # list pools and indent
37 printf "Which pool do you want to search for orphans? "
45 elif [ $# -eq 1 ] ;then
48 error_out
"Usage: $0 [pool]"
51 echo "Pool is \"$pool\"."
53 echo "Note: output files produced will be tagged with the current timestamp -- ${timestamp}."
55 echo "running 'rados ls' at $(date)"
56 rados
ls --pool="$pool" >"$rados_out" 2>"$rados_err"
57 if [ "$?" -ne 0 ] ;then
58 error_out
"rados ls" "$rados_err"
60 sort -u "$rados_out" >"$temp_file"
61 mv -f "$temp_file" "$rados_out"
63 echo "running 'radosgw-admin bucket radoslist' at $(date)"
64 radosgw-admin bucket radoslist
>"$rgwadmin_out" 2>"$rgwadmin_err"
65 if [ "$?" -ne 0 ] ;then
66 error_out
"radosgw-admin radoslist" "$rgwadmin_err"
68 sort -u "$rgwadmin_out" >"$temp_file"
69 mv -f "$temp_file" "$rgwadmin_out"
71 echo "computing delta at $(date)"
72 ceph-diff-sorted
"$rados_out" "$rgwadmin_out" |
grep "^<" |
sed 's/^< *//' >"$delta_out"
73 # use PIPESTATUS to get at exit status of first process in above pipe;
74 # 0 means same, 1 means different, >1 means error
75 if [ "${PIPESTATUS[0]}" -gt 1 ] ;then
76 error_out
"ceph-diff-sorted"
79 found
="$(wc -l < $delta_out)"
80 possible
="$(wc -l < $rados_out)"
81 percentage
=$
(expr 100 \
* $found / $possible)
83 echo "$found potential orphans found out of a possible $possible (${percentage}%)."
84 echo "The results can be found in ${delta_out}."
85 echo " Intermediate files: ${rados_out} and ${rgwadmin_out}"
87 echo "*** WARNING: This is EXPERIMENTAL code and the results should be used"
88 echo "*** only with CAUTION!"
90 echo "Done at $(date)."