From 4dda4ade6645802f7209cea8e7a77d054d624e11 Mon Sep 17 00:00:00 2001 From: Cody Cook Date: Thu, 7 Dec 2017 21:58:39 -0800 Subject: [PATCH] Resolve "When no directories existed in the volume, tar felt obligated to error out..." --- share_lun_ui_fix.sh | 96 +++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/share_lun_ui_fix.sh b/share_lun_ui_fix.sh index 2061f63..f3b255d 100755 --- a/share_lun_ui_fix.sh +++ b/share_lun_ui_fix.sh @@ -101,56 +101,60 @@ EOF ........................ ........................ EOF - cat > "$path"/snapshot.conf << EOF -0 0 0 * 0 0 0 -EOF - echo " done with /$volume/$item." -} + cat > "$path"/snapshot.conf << EOF + 0 0 0 * 0 0 0 + EOF + echo " done with /$volume/$item." + } -backup_configs() { -cd "/$volume/._share/" -tar -cf "/var/backups/$volume_sharelunconfig.$(date +%s).tar" ./* -} + backup_configs() { + cd "/$volume/._share/" + tar -cf "/var/backups/$volume_sharelunconfig.$(date +%s).tar" ./* 2>/dev/null + } -echo "===============================" -echo "Share and iSCSI Rebuild v6.8.0" -echo "===============================" -echo "Querying readynasd for list of volumes..." - -x=$(rn_nml -g volumes 2>/dev/null) # find if readynasd is running - -if [[ $? -eq 0 ]]; then # if readynasd was successful - x=$(echo "$x"| grep "resource-id" | sed 's/^.*id="//;s/".*//;') # then parse it - readynasd=1 -elif [[ $? -eq 1 ]] ; then # but if it wasn't - echo "readynasd not available; doing alternative lookup for shares" # inform intent - x=$(find / -maxdepth 2 -name "._share" | sed 's/^\///g;s/\/.*//') # create new list -fi - -number=$(echo "$x" | wc -w) - -if [[ ! $number ]]; then - echo "No volumes found!" - exit 1 -else - echo "$number volume(s) found." - echo -n "Beginning in 3..."; sleep 1; echo -n " 2..."; sleep 1; echo " 1..."; sleep 1 echo "===============================" - echo "=== All right! Time to go! ===" + echo "Share and iSCSI Rebuild v6.8.0" echo "===============================" - for volume in $x; do - echo "= Investigating volume /$volume..." - objects=$(cd /"$volume"; ls -dA */ | egrep -v "^.apps\/$|^home\/$|^.purge\/$|^._share\/$|^.timemachine\/$|^.vault\/$|^.TemporaryItems\/$" | sed 's/\/$//') - echo "= Objects found:" $objects - backup_configs - for item in $objects; do - echo "== Reviewing $item" - if ls -QdA /"$volume"/"$item"/.iscsi >/dev/null 2>&1; then - iscsi_create - else - share_create - fi - done + echo "Querying readynasd for list of volumes..." + + x=$(rn_nml -g volumes 2>/dev/null) # find if readynasd is running + + if [[ $? -eq 0 ]]; then # if readynasd was successful + x=$(echo "$x"| grep "resource-id" | sed 's/^.*id="//;s/".*//;') # then parse it + readynasd=1 + elif [[ $? -eq 1 ]] ; then # but if it wasn't + echo "readynasd not available; doing alternative lookup for shares" # inform intent + x=$(find / -maxdepth 2 -name "._share" | sed 's/^\///g;s/\/.*//') # create new list + fi + + number=$(echo "$x" | wc -w) + + if [[ ! $number ]]; then + echo "No volumes found!" + exit 1 + else + echo "$number volume(s) found." + echo -n "Beginning in 3..."; sleep 1; echo -n " 2..."; sleep 1; echo " 1..."; sleep 1 + echo "===============================" + echo "=== All right! Time to go! ===" + echo "===============================" + for volume in $x; do + echo "= Investigating volume /$volume..." + objects=$(cd /"$volume"; ls -dA */ 2>/dev/null | egrep -v "^.apps\/$|^home\/$|^.purge\/$|^._share\/$|^.timemachine\/$|^.vault\/$|^.TemporaryItems\/$" | sed 's/\/$//') + if [[ $? == 2 ]]; then + echo "No shares or LUNs found." + else + echo "= Objects found:" $objects + backup_configs + for item in $objects; do + echo "== Reviewing $item" + if ls -QdA /"$volume"/"$item"/.iscsi >/dev/null 2>&1; then + iscsi_create + else + share_create + fi + done + fi echo "= done with /$volume" done