repair_link.sh 1.1 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#!/bin/bash

# This script is used to repaire links when you what to move TDengine
# data to other places and to access data.

# Read link path
read -p "Please enter link directory such as /var/lib/taos/tsdb: " linkDir

while true; do
    if [ ! -d $linkDir ]; then
        read -p "Paht not exists, please enter the correct link path:" linkDir
        continue
    fi
    break
done

declare -A dirHash

for linkFile in $(find -L $linkDir -xtype l); do
    targetFile=$(readlink -m $linkFile)
    echo "targetFile: ${targetFile}"
    # TODO : Extract directory part and basename part
    dirName=$(dirname $(dirname ${targetFile}))
    baseName=$(basename $(dirname ${targetFile}))/$(basename ${targetFile})

    # TODO : 
    newDir="${dirHash["$dirName"]}"
    if [ -z "${dirHash["$dirName"]}" ]; then
        read -p "Please enter the directory to replace ${dirName}:" newDir

        read -p "Do you want to replcace all[y/N]?" replcaceAll
        if [[ ( "${replcaceAll}" == "y") || ( "${replcaceAll}" == "Y") ]]; then
            dirHash["$dirName"]="$newDir"
        fi
    fi

    # Replcace the file
    ln -sf "${newDir}/${baseName}" "${linkFile}"
done