쉘 스크립트 백업 및 복원

쉘 스크립트 백업 및 복원

특정 디렉터리를 백업한 다음 복원하는 스크립트를 만들려고 했습니다. 백업은 예상대로 작동하지만 복원 기능을 실행하려고 하면 다음 오류가 발생합니다.

해결되었습니다. 작업 코드는 다음과 같습니다.

스크립트

#!/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

관련 정보