shellコマンドによるファイルのバックアップとリカバリ
5661 ワード
#!/bin/bash
#
backupdir()
{
dirtest
echo "Backupping..."
echo $DIRECTORY
#mkdir $newdir
# DIRECTORY backup.tar.gz /tmp
tar -zcvf /tmp/backup.tar.gz $DIRECTORY
}
#
restoredir()
{
dirtest
echo "Restoring..."
echo $DIRECTORY
tar -zxvf /tmp/backup.tar.gz
}
#
dirtest()
{
echo "please enter the directory name of backup file:"
read DIRECTORY
#read newdir
if [ ! -d $DIRECTORY ] #
then
echo "sorry,$DIRECTORY is not a directory!"
exit 1
fi
#cd $DIRECTORY
}
clear
ANS=Y
while [ $ANS = Y -o $ANS = y ]
do
echo "========================"
echo "= Backup-Restore Mune ="
echo "++++++++++++++++++++++++"
echo "+ 1:Backup Directory +"
echo "+ 2:Restore Directory +"
echo "+ 0:Exit +"
echo "++++++++++++++++++++++++"
echo "Please enter a choice(0-2):"
read CHOICE
case "$CHOICE" in
1) backupdir;;
2) restoredir;;
0) exit 1;;
*) echo "Invalid Choice!"
exit 1;;
esac
if [ $? -ne 0 ] #$? 0
then
echo "Program encounter error!" #
exit 2
else
echo "Operate successfully!"
fi
echo "Would you like to continue? Y/y to continue,any other key to exit:"
read ANS
clear
done