Permalink
Browse files

refactor display of possible restore bins to sort in ascending order …

…by time
  • Loading branch information...
1 parent 09fcf1c commit e8c6ff8158871b0c35e4c40c05bbbf069375d98c @falconindy committed Aug 26, 2010
Showing with 10 additions and 9 deletions.
  1. +10 −9 squashfu
View
@@ -338,34 +338,35 @@ action_resquash_now () {
}
action_restore () {
-
[[ -z $1 ]] && die "Missing parameter from restore. Provide a full path to the restore target."
[[ $UID != 0 ]] && die "Must be root to restore."
mount_squash || die "Failed to mount seed"
- IFS=$'\n' read -r -d'\0' -a results < <(find "$BINS_DIR"/*/"$1" -maxdepth 0 2>/dev/null)
+ IFS=$'\n' read -r -d'\0' -a result < <(find "$BINS_DIR"/*/"$1" -maxdepth 0 2>/dev/null)
- declare -a snaps
[[ -e "$SQUASH_MOUNT/$1" ]] && snaps[0]=$(stat -c %Z "$SQUASH_MOUNT/$1")
if [[ -z ${snaps[0]} && ${#results[@]} -eq 0 ]]; then
unmount_squash
die "Target not found: '$1'"
fi
+ # print results, ghetto mapping sort against inventory
info "Found ${1##*/} in the following backups:"
[[ -n ${snaps[0]} ]] && printf " 0\t%s\n" "$(date --date=@${snaps[0]})"
- for result in "${results[@]}"; do
- local bin=$(sed -n "s|$BINS_DIR/\([0-9]*\)$1|\1|p" <<< "$result")
- local bkupdate=$(sed -n "s|^$bin:\([0-9]*\)$|\1|p" $BINVENTORY)
- snaps[$bin]=$bkupdate
- printf " %d\t%s\n" $bin "$(date --date="@$bkupdate")"
+ declare -a snaps
+ IFS=$'\n' read -r -d'\0' -a mapping < "$BINVENTORY"
+ for line in "${mapping[@]}"; do
+ IFS=':' read bin stamp <<< "$line"
+ for res in "${result[@]}"; do
+ [[ $res =~ $BINS_DIR/$bin$1 ]] && printf " %d\t%s\n" $bin "$(date --date="@$stamp")"
+ done
done
read -p "Which snapshot to restore from? " reply
- [[ -z $reply || -z ${snaps[$reply]} ]] && die "Invalid bin"
+ [[ -z $reply || -z ${snaps[$reply]} || ${reply//[0-9]/} ]] && die "Invalid bin"
local bin_list=($(sed -n 's/[\t\ ]*\([0-9]*\):.*/\1/p' "$BINVENTORY"))
local num=$(grep -nh "^$reply:" $BINVENTORY | cut -d: -f1)

0 comments on commit e8c6ff8

Please sign in to comment.