@@ -20,21 +20,30 @@ prune_snapshot() {
20
20
done
21
21
}
22
22
23
- # First prune all incomplete / failed snapshot directories
24
- prune_dirs=" $( ls -1 " $GHE_DATA_DIR " /[0-9]* /incomplete 2> /dev/null || true) "
25
- prune_num=$( echo " $prune_dirs " | grep -v ' ^$' | wc -l)
23
+ # Prune if backup is not running
24
+ # if [ ! -f "$GHE_DATA_DIR/in-progress" ] && [ ! -f "$GHE_DATA_DIR/in-progress-restore" ]; then
25
+ # Check for backup or restore in-progress file
26
+ inprogress_file=$( find $GHE_DATA_DIR -maxdepth 1 -type f \( -name " in-progress" -o -name " in-progress-restore" \) -print -quit)
27
+ if [ -z " $inprogress_file " ]; then
28
+ # First prune all incomplete / failed snapshot directories
29
+ prune_dirs=" $( ls -1 " $GHE_DATA_DIR " /[0-9]* /incomplete 2> /dev/null || true) "
30
+ prune_num=$( echo " $prune_dirs " | grep -v ' ^$' | wc -l)
26
31
27
- if [ $prune_num -gt 0 ]; then
28
- log_info Pruning $prune_num " failed snapshot(s) ..."
29
- echo " $prune_dirs " | sed ' s@/incomplete$@@' | prune_snapshot
30
- fi
32
+ if [ $prune_num -gt 0 ]; then
33
+ log_info Pruning $prune_num " failed snapshot(s) ..."
34
+ echo " $prune_dirs " | sed ' s@/incomplete$@@' | prune_snapshot
35
+ fi
31
36
32
- # Now prune all expired snapshots. Keep GHE_NUM_SNAPSHOTS around.
33
- snapshot_count=$( ls -1d " $GHE_DATA_DIR " /[0-9]* 2> /dev/null | wc -l)
37
+ # Now prune all expired snapshots. Keep GHE_NUM_SNAPSHOTS around.
38
+ snapshot_count=$( ls -1d " $GHE_DATA_DIR " /[0-9]* 2> /dev/null | wc -l)
34
39
35
- if [ " $snapshot_count " -gt " $GHE_NUM_SNAPSHOTS " ]; then
36
- prune_dirs=" $( ls -1d " $GHE_DATA_DIR " /[0-9]* | sort -r | awk " NR>$GHE_NUM_SNAPSHOTS " ) "
37
- prune_num=$( echo " $prune_dirs " | grep -v ' ^$' | wc -l)
38
- log_info Pruning $prune_num " expired snapshot(s) ..."
39
- echo " $prune_dirs " | prune_snapshot
40
+ if [ " $snapshot_count " -gt " $GHE_NUM_SNAPSHOTS " ]; then
41
+ prune_dirs=" $( ls -1d " $GHE_DATA_DIR " /[0-9]* | sort -r | awk " NR>$GHE_NUM_SNAPSHOTS " ) "
42
+ prune_num=$( echo " $prune_dirs " | grep -v ' ^$' | wc -l)
43
+ log_info Pruning $prune_num " expired snapshot(s) ..."
44
+ echo " $prune_dirs " | prune_snapshot
45
+ fi
46
+ else
47
+ log_info " Detected a running backup/restore process, please wait until that process is complete to prune expired/incomplete snapshots." 1>&2
48
+ log_info " If no such process is running, please remove the " $GHE_DATA_DIR /in-progress* " file and retry again." 1>&2
40
49
fi
0 commit comments