But here are steps I took.
(1) Problem:
You have two types of frugal Puppy pupsave file backups with each having a given name format.
You also want to be able to do a straight copy if those names do not match the input file.
In the case of the pupsave backups, the destination file name has to have a date-time stamp in the filename removed.
In the case of another file name, it has to be passed unchanged.
(2) logic and solution
This script needs to be run from a terminal. But it is commented for logic.
From a terminal/command line, you type the name you gave this script along with a file name with path.
Backed up pupsave files using hotbkp, or dated backup utilities have a format like this:
hotbkp is /mnt/home/pupsave.2fs.BKP-11.10.04_12.30
dated backup is /mnt/home/pupsave-11.10.04_12.30.2fs
other files can be any path/file name.
Here is what I came up with some of which is used in my PupsaveRestore.sh
It also shows that I try to solve a problem step by step.
I called this short script fname.sh and after copying and saving it, you will have to make the file executable.
To run from terminal command line #./fname path/filename
Code: Select all
#! /bin/bash
PUPSAVE_FILE=$1 #Get source file from command line
FS="$PUPSAVE_FILE" #Give variable shorter name
LAST=${FS##*/} # Removes Path from filename
#FRST=${LAST%%save*};echo FRST=$FRST
#LST=${LAST##*save};echo LST=$LST
chk=$(echo ${LAST/BKP}) #Check for "BKP" in source file name and delete in variable chk
if [ ! "$chk" = "$LAST" ]; then # If chk does not equal LAST, "BKP" existed in name process name
# chk=$(echo $LAST | grep "BKP")
# if [ $chk = $LAST ]; then
newname=`echo $LAST | sed "s/...................$//"` #That is 19 dots in sed Removes date-time
else newname="$LAST" #If "BKP" did not exist in LAST newname is same as LAST
fi
EXT1=${LAST##*.} # Get LAST extension
#Check LAST extension and process if one of 2fs,3fs,4fs otherwise pass newname unchanged
if [ $EXT1 = "2fs" ]
then
EXT2=.$EXT1
newname=`echo $LAST | sed 's/-.*'$EXT2'/-'$EXT2'/' | sed 's/-//'`
fi
if [ $EXT1 = "3fs" ]
then
EXT2=.$EXT1
newname=`echo $LAST | sed 's/-.*'$EXT2'/-'$EXT2'/' | sed 's/-//'`
fi
if [ $EXT1 = "4fs" ]
then
EXT2=.$EXT1
newname=`echo $LAST | sed 's/-.*'$EXT2'/-'$EXT2'/' | sed 's/-//'`
fi
echo PUPSAVE_FILE = $PUPSAVE_FILE #Show Source file name
echo newname = $newname #Show modified name for copying
echo EXT2 = $EXT2 #Show filename extension of source file in LAST