Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been trying to create a script that backups up a certain directory and then restores the directory. The backup works as it should but when I try run the restore function I get the following error;

Solved,Working code below

Script

#!/bin/bash

ROOT="/Users/Rory/Documents"
ROOT_EXCLUDE="--exclude=/dev --exclude=/proc --exclude=/sys --exclude=/temp --exclude=/run --exlucde=/mnt --exlcude=/media --exlude=/backup2.tgz"
DESTIN="/Users/Rory/test/"
BACKUP="backup.tgz"
CREATE="/dev /proc /sys /temp /run /mnt /media "

if [ "$USER" != "root" ]; then
    echo "You are not the root user"
    echo "To use backup please use: sudo backup"
    exit
fi

clear

echo "************************************************"
echo "********* Backup Menu **************************"
echo "************************************************"

OPTIONS="BACKUP RESTORE DESTINATION EXIT"
LIST="1)BACKUP 2)RESTORE 3)DESTINATION 4)EXIT"

select opt in $OPTIONS; do
if [ "$opt" = "EXIT" ]; then
    echo "GOODBYE!"
    sleep 3
    clear
    exit

elif [ "$opt" = "BACKUP" ]; then
    echo "BACKING UP FILES..."
    sleep 2
    tar cvpfz $DESTIN/backup.`date +%d%m%y_%k:%M`.tgz $ROOT $ROOT_EXCLUDE_DIRS
    echo "BACKUP COMPLETE"
    sleep 2
    exit

elif [ "$opt" = "RESTORE" ]; then
    echo "RESTOTING FILES..."
    sleep 2
    echo $BACKUP
    tar xvpfz $DESTIN/$BACKUP -C /
    sleep 2
    if [[ -e "/proc" ]]; then
            echo "$CREATE already exists! "
    else
            mkdir $CREATE
            echo "$CREATE are created! "
    fi
    echo "RESTORE COMPLETE..."
    exit
elif [ "$opt" = "DESTINATION" ]; then
    echo "CURRENT DESTINATION: $DEST_DIR/backup.`date +%d/%m/%y_%k:%M`.tgz "
    echo "TO CHANGE ENTER THE NEW DESTINATION..."
    echo "TO LEAVE IT AS IS JUST PRESS ENTER..."
    read NEW_DESTIN

    #IF GREATER THEN 0 ASSIGN NEW DESTINATION
    if [ ${#NEW_DESTIN} -gt 0 ]; then
            DESTIN = "$NEW_DESTIN"
    fi
    clear
    echo $BANNER1
    echo $BANNER2
    echo $BANNER3
    echo $LIST


else
    clear
    echo "BAD INPUT!"
    echo "ENTER 1 , 2, 3 or 4.."
    echo $LIST


fi
done
share|improve this question
    
It looks like $BACKUP was undefined when you ran the script and reached the line tar xvpfz $BACKUP -C /. I see that it is defined at the top of the script but your 'DESTINATION' option allows you to change a different variable (NEW_DESTIN). – gogoud Mar 29 '15 at 16:42
    
I have taken out the DESTINATION function to eliminate that error but still getting the same error when trying to restore – Hayes121 Mar 29 '15 at 16:48
    
does the line before correctly echo backup.tgz? – gogoud Mar 29 '15 at 16:52
    
Yep that prints backup.tgz, should I be calling the tar command to look in the $DESTIN folder? ( ie tar xvpfz $DESTIN $BACKUP -C / ) – Hayes121 Mar 29 '15 at 16:55
    
Your backup is backup.date +%d%m%y_%k:%M.tgz which is backup.290315_20:00.tgz and you are trying to extract backup.tgz which probably does not exists. – taliezin Mar 29 '15 at 16:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.