]> lifelog.hopto.org Git - wb-shell-scripts.git/commitdiff
Enabled listing of remote target not in config.
authorWill Budic <redacted>
Mon, 16 Feb 2026 01:05:05 +0000 (12:05 +1100)
committerWill Budic <redacted>
Mon, 16 Feb 2026 01:05:05 +0000 (12:05 +1100)
linux-B_L_R_via_sshfs/backup.config
linux-B_L_R_via_sshfs/backup.sh
linux-B_L_R_via_sshfs/list.sh

index 5e9c9a8d17b6c4ac3f68a0ae2960bb082d29df69..7e1b8881e983dbd13915f169193995aec01ec001 100644 (file)
@@ -7,6 +7,11 @@ THIS_MACHINE=$(uname -n)
 DEST_SERVER=192.168.1.69
 # And its default mount point target (should not be changed).
 TARGET="/mnt/$DEST_SERVER"
+
+# Set to IS_LOCAL=1 if for some reason is backing up on the same machine.
+# Reason could be to test things or target is another drive or device for now.
+IS_LOCAL=0
+
 DPATH=/usr/local/bin:/usr/bin:/bin
 EXT_ENC="tar.xz.enc"
 EXT_LST="lst.xz"
index d14277711623ffd5a6f4fa9ecbe6e6baa54ac87a..edc94317e9927f2ff44e7ad491324ee805e5a119 100755 (executable)
@@ -127,6 +127,7 @@ then
         sshfs "$USER@$DEST_SERVER:$BACKUP_DIRECTORY" $TARGET -o allow_other
         [[ $? -eq 1 ]] && echo "Error aborting! '$TARGET' is not valid!" && exit 2
         echo "Mounted $TARGET."
+        MOUNTED=1
     fi
 else
     [[ $1 ]] && TARGET=$1
@@ -345,12 +346,13 @@ function DoBackup () {
     [[ -f "/home/will/uvar.sh" ]] && /home/will/uvar.sh -n "LAST_BACKUP_DATE" -v "$BACKUP_END";
     
     echo -e "Done with backup of $HOME on "`date`", have a nice day!";
-    
+    umount "$TARGET"    
 }
 ##
 crontab -l>crontab.lst
 code --list-extensions > vs_code_extensions.lst
 DoBackup
+
 exit 0
 
 
index a01a825aed9b8e235d57633a6026f3bc46d1bdb8..15cc52fc4dbff2b94a5f71e6faf5db6b43039a58 100755 (executable)
@@ -6,44 +6,77 @@ CONFIG_FILE="$HOME/.config/backup.config"
 else
 CONFIG_FILE="$SRC_DIR/backup.config"
 fi 
-. $CONFIG_FILE
+
+echo -e "Processing from config: $CONFIG_FILE"
+source $CONFIG_FILE
+
 #
 echo -e "\n--------------------------------------------------------------------------------------------------------------"
 echo -e " This is an backup archive restore list creator, use this program from the directory you restore to locally."
 echo -e " Backup location is DEST_SERVER='$DEST_SERVER'"
 echo -e " Restore location is PWD='`pwd`'"
 echo -e "--------------------------------------------------------------------------------------------------------------"
-echo -e "Syntax: $0 {{-target=/some/path} {--tar} | {restore.lst}\n}"
+echo -e "Syntax: $0 {{--target=/some/path} {--tar | restore.lst}"
 echo "After listing, to restore from the backup, use the list with the restore shell script."
 echo "Like: $SRC_DIR/restore.sh ./restore.lst"
 echo "To restore from a local drive or mount:"
 echo "$SRC_DIR/restore.sh --target=/mnt/$user/samsung  ./restore.lst"
-echo -e "Usage: $0 --tar   - Instruction to generate and text tar listing from latest archive. In text format to be viewed.\n" 
+echo -e "\nOptions/Instructions:\n  --tar  - Instruction to generate and text tar listing from latest archive. In text format to be viewed.\n" 
+
 [[ "$1" == '-?' || "$1" == '-h' ]] && exit;
 
-echo -e "Processing from config: $CONFIG_FILE"
+
+
 if [[ ! -z "$1" && $1 =~ ^--target ]] 
-then
-    TARGET=$(echo $1 | awk -v bd="$BACKUP_DIRECTORY" -F= '{print $2"/"bd}')
+then    
+    TARGET=$(echo $1 | awk -F= '{print $2}')     
+    TARGET_MOUNT="$TARGET"
+    DEST_SERVER="$TARGET"
+    TARGET_MOUNT=$(echo $TARGET |  perl -n -e '/(\w*)/;print "/mnt/$1"')    
     echo -e "[[[$TARGET]]]\n"
-    if [[ ! -d "$TARGET" ]] 
+    if [[ ! -d "$TARGET_MOUNT" || $(ls -l "$TARGET_MOUNT"| perl -ne '/\w*(\d)/gs; print $1') == 0 ]] 
     then
-        echo -e "\nTarget location doesn't exits: $TARGET"
-        echo -e "Available Media:"
-        find /media/$USER -maxdepth 2 -type d -print         
-        echo -e "\nAvailable Mounts:"
-        find /mnt/ -maxdepth 2 -type d -not -path '*/\.*' -print
-        exit 1
-    else
-        IS_LOCAL=1
-        DEST_SERVER=$THIS_MACHINE
-    fi    
+        echo -e "Trying to mount to remote '$USER@$DEST_SERVER:$BACKUP_DIRECTORY' to $TARGET";        
+        sshfs "$USER@$DEST_SERVER:$BACKUP_DIRECTORY" $TARGET_MOUNT -o allow_other 
+        if [[ $? -eq 1 ]]
+        then
+            echo -e "\nError aborting! '$TARGET_MOUNT' is not valid!"       
+            echo -e "\nTarget location doesn't exits: $TARGET"
+            echo -e "Available Media:"
+            find /media/$USER -maxdepth 2 -type d -print         
+            echo -e "\nAvailable Mounts:"
+            find /mnt/ -maxdepth 2 -type d -not -path '*/\.*' -print
+            
+            echo -e "\n The required mount point should be: $TARGET_MOUNT"
+            echo -e "Will create it for you, then try again running $0 again!"
+            sudo mkdir $TARGET_MOUNT && sudo chmod +w $TARGET_MOUNT && sudo chown $USER:$USER  $TARGET_MOUNT;
+            exit 1
+        else
+            echo "Mounted $TARGET_MOUNT."                        
+        fi      
+    fi      
+    TARGET="$TARGET_MOUNT"
 fi
+
+
 if [[ -z $IS_LOCAL ]];
 then
-[[ ! -d "$TARGET" ]] && echo "Exiting mount point not setup!" && exit 1
-    echo -e "Accessing  -> $USER@$DEST_SERVER:$BACKUP_DIRECTORY"
-    sshfs "$USER@$DEST_SERVER:$BACKUP_DIRECTORY" $TARGET -o allow_other > /dev/null 2>&1
+    echo -e "Mounting  -> $USER@$DEST_SERVER:$BACKUP_DIRECTORY to $TARGET"
+    sshfs "$USER@$DEST_SERVER:$BACKUP_DIRECTORY" $TARGET -o allow_other 
+    # > /dev/null 2>&1
+    if [[ ! -d "$TARGET" ]] 
+    then 
+        echo "Exiting mount point $TARGET not setup!" 
+        exit 1
+    fi
+    MOUNTED=1
+fi
+
+if [[ $(ls -l $TARGET | perl -ne '/\w*(\d)/gs; print $1') == 0 ]]
+then
+    echo "Exiting $TARGET is empty has no files!" 
+    umount $TARGET
+    exit 2
 fi
 
 if [[ ! -z "$1" && "$1" == "--tar" ]] 
@@ -53,14 +86,14 @@ then
  gpg --decrypt --batch --passphrase $GPG_PASS $BACKUP_FILE | pv -N "Status" -pw 80 | tar -Jtv \
  > "$BACKUP_FILE.list"
  echo -e "Crated tar list of -> $BACKUP_FILE\n"
- exit
+ exit 0
 fi
 
 INDEX=$(ls -lht $TARGET/$THIS_MACHINE-*.$EXT_LST | head -n 1);
 if [[ -z $INDEX ]]
 then
 echo -e "FAILED to access target backup directory!\n"
-exit 0
+exit 1
 fi
 
 INDEX_FILE=$(echo "$INDEX" | awk '{print $9}')
@@ -101,6 +134,8 @@ echo -e "Warning - existing directories that have been found and listed above."
 ~/uvar.sh -d "BCK_LST_CHK" > /dev/null
 fi
 
+[[ -z && "$MOUNTED"]] umount "$TARGET"
+
 exit
 # This script originated from : https://lifelog.hopto.org/gitweb/?p=wb-shell-scripts.git
 # older versions https://github.com/wbudic/B_L_R_via_sshfs