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" ]]
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}')
~/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