]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw-orphan-list
bump version to 15.2.4-pve1
[ceph.git] / ceph / src / rgw / rgw-orphan-list
1 #!/usr/bin/env bash
2
3 # version 1
4
5 # IMPORTANT: affects order produced by 'sort' and 'ceph-diff-sorted'
6 # relies on this ordering
7 export LANG=C
8
9 out_dir="."
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"
18
19 error_out() {
20 echo "An error was encountered while running '$1'. Aborting."
21 if [ $# -gt 1 ] ;then
22 echo "Review file '$2' for details."
23 fi
24 echo "***"
25 echo "*** WARNING: The results are incomplete. Do not use! ***"
26 echo "***"
27 exit 1
28 }
29
30 prompt_pool() {
31 echo "Available pools:"
32 rados lspools >"$temp_file" 2>"$lspools_err"
33 if [ "$?" -ne 0 ] ;then
34 error_out "rados lspools" "$lspools_err"
35 fi
36 sed 's/^/ /' $temp_file # list pools and indent
37 printf "Which pool do you want to search for orphans? "
38 local mypool
39 read mypool
40 echo $mypool
41 }
42
43 if [ $# -eq 0 ] ;then
44 pool="$(prompt_pool)"
45 elif [ $# -eq 1 ] ;then
46 pool="$1"
47 else
48 error_out "Usage: $0 [pool]"
49 fi
50
51 echo "Pool is \"$pool\"."
52
53 echo "Note: output files produced will be tagged with the current timestamp -- ${timestamp}."
54
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"
59 fi
60 sort -u "$rados_out" >"$temp_file"
61 mv -f "$temp_file" "$rados_out"
62
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"
67 fi
68 sort -u "$rgwadmin_out" >"$temp_file"
69 mv -f "$temp_file" "$rgwadmin_out"
70
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"
77 fi
78
79 found="$(wc -l < $delta_out)"
80 possible="$(wc -l < $rados_out)"
81 percentage=$(expr 100 \* $found / $possible)
82
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}"
86 echo "***"
87 echo "*** WARNING: This is EXPERIMENTAL code and the results should be used"
88 echo "*** only with CAUTION!"
89 echo "***"
90 echo "Done at $(date)."