zefie icon

btrfs-restore (for recovery)

zefie | PRO | 08/23/18 11:03:09 AM UTC | 0 ⭐ | 777 👁️ | Never ⏰ | []
Bash |

780 B

|

None

|

0 👍

/

0 👎

#/bin/bash
Z_DISK="sdc5"
 
if [ ! -z "${2}" ]; then
        if [ -e "/dev/${2}" ]; then
                Z_DISK="${2}"
        fi
fi
 
if [ ! -z "${1}" ]; then
        if [ "${1:0:1}" == "/" ]; then
                Z_REG="${1}"
        else
                Z_REG="/${1}"
        fi
        Z_REG=$(echo "${Z_REG}" | sed -e 's#/#(|/#g' | sed -e 's#*#(|.*#g')
        Z_REG_CLOSE_COUNT=$(awk -F'(' '{print NF-1}' <<< "${Z_REG}")
        Z_C=1
        while [[ ${Z_C} -le ${Z_REG_CLOSE_COUNT} ]]; do
                Z_REG=$(echo "${Z_REG})")
                let Z_C=Z_C+1
        done
        Z_REG=$(echo "^/${Z_REG}\$"  | sed -e 's#/(|/#/(|#')
        yes a | /root/tmp/btrfs-progs/btrfs restore -vmo --path-regex ${Z_REG} /dev/${Z_DISK} /root/tmp/out 2>/root/tmp/err.txt
fi

Comments