Remove the first two lines if you want to run in Prompt.
The backups are store only by date, so if you backup the same pupsave twice in a day, it will overwrite.
Code: Select all
#!/bin/sh
tail -n +4 $0 > /tmp/backupscript.txt
exec rxvt -e sh /tmp/backupscript.txt
DATE=`date +%e-%m-%y`
if [ -f /tmp/PUPSAVE ]
then
rm /tmp/PUPSAVE
fi
echo "[r]estore or [b]ackup"
read RB
if [ "$RB" = r ];then
FND_BACKUP="`find /mnt/home/ -maxdepth 3 -mount -type f -name *-??-??`"
echo "$FND_BACKUP" >> /tmp/PUPSAVE
NUM=`wc -l /tmp/PUPSAVE | tr -s ' ' | cut -f 2 -d ' '`
echo Choose which BackUp you would like to Restore.
CHOOSE=1
for ONECHOICE in `cat /tmp/PUPSAVE | tr '\n' ' '`
do
ONEPART="`echo -n "$ONECHOICE" | cut -f 1 -d ','`"
echo -e "${CHOOSE} ${ONEPART}"
CHOOSE=`expr $CHOOSE + 1`
done
read SAVENUM
PUPSAVE="`cat /tmp/PUPSAVE | tr '\n' ' ' | cut -f $SAVENUM -d ' '`"
NAME="${PUPSAVE%/*}"
NAME="${NAME%???}.${NAME:${#NAME}-3}"
echo $NAME
echo Are you sure? This will remove the previous Savefile. [y/n]
read sureornot
if [ "$sureornot" = n ];then
echo Goodbye
read
fi
if [ "$sureornot" = y ];then
echo removing $NAME
rm $NAME
echo Copying $PUPSAVE to $NAME...Auto-close when done.
cp -p "$PUPSAVE" "$NAME"
fi
fi
if [ "$RB" = b ];then
FND_PUPSAVE="`find /mnt/home/ -maxdepth 2 -mount -type f -name *save*.[23]fs`"
echo "$FND_PUPSAVE" >> /tmp/PUPSAVE
NUM=`wc -l /tmp/PUPSAVE | tr -s ' ' | cut -f 2 -d ' '`
case $NUM in
0)
echo No pupsave found
read
;;
1)
NAME="`echo $FND_PUPSAVE | tr -d "."`"
if [ -d $NAME ];then
echo $NAME exist.
else
mkdir $NAME
fi
echo Copying to $NAME ... Auto-Close when completed
cp -p "$FND_PUPSAVE" "$NAME/$DATE"
;;
*)echo Choose which save file you would like to backup.
CHOOSE=1
for ONECHOICE in `cat /tmp/PUPSAVE | tr '\n' ' '`
do
ONEPART="`echo -n "$ONECHOICE" | cut -f 1 -d ','`"
echo -e "${CHOOSE} ${ONEPART}"
CHOOSE=`expr $CHOOSE + 1`
done
read SAVENUM
PUPSAVE="`cat /tmp/PUPSAVE | tr '\n' ' ' | cut -f $SAVENUM -d ' '`"
NAME="`echo $PUPSAVE | tr -d "."`"
if [ -d $NAME ];then
echo $NAME exist.
else
mkdir $NAME
fi
echo Copying to $NAME ... Auto-Close when completed
cp -p "$PUPSAVE" "$NAME/$DATE"
;;
esac
fi
if [ -f "$NAME/ $DATE" ]
then
mv "$NAME/ $DATE" "$NAME/$DATE"
fi
rm /tmp/PUPSAVE