From 03f985c64c2195ce14d61a55de656d756d46c8e3 Mon Sep 17 00:00:00 2001 From: Will Budic Date: Mon, 16 Feb 2026 12:05:05 +1100 Subject: [PATCH] Enabled listing of remote target not in config. --- linux-B_L_R_via_sshfs/backup.config | 5 ++ linux-B_L_R_via_sshfs/backup.sh | 4 +- linux-B_L_R_via_sshfs/list.sh | 79 +++++++++++++++++++++-------- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/linux-B_L_R_via_sshfs/backup.config b/linux-B_L_R_via_sshfs/backup.config index 5e9c9a8..7e1b888 100644 --- a/linux-B_L_R_via_sshfs/backup.config +++ b/linux-B_L_R_via_sshfs/backup.config @@ -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" diff --git a/linux-B_L_R_via_sshfs/backup.sh b/linux-B_L_R_via_sshfs/backup.sh index d142777..edc9431 100755 --- a/linux-B_L_R_via_sshfs/backup.sh +++ b/linux-B_L_R_via_sshfs/backup.sh @@ -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 diff --git a/linux-B_L_R_via_sshfs/list.sh b/linux-B_L_R_via_sshfs/list.sh index a01a825..15cc52f 100755 --- a/linux-B_L_R_via_sshfs/list.sh +++ b/linux-B_L_R_via_sshfs/list.sh @@ -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 -- 2.34.1