I'm writing a backup script for my email and cloud service.
For simplicity, I only posted the mail-backup part here.
Basically, I have a Host-Machine with some Virtual Boxes running in it.
These Virtual Boxes access Host-Machines' /mnt/alias/storage/ where there is the vmail folder (called shishaMail in my case)
(Following might not be necessary information)
I would like to say that everything within /mnt/alias/ is an ln -s from /mnt/rack/* with pretty names.
In this rack folder are the mounts of the drives.
(Not necessary information END)
Here is my script
#!/bin/bash
# backup script
BASEURL="/mnt/alias/backup"
MAILURL="/mnt/alias/storage/shishaMail"
DAY=`eval date +"%d"`
MONTH=`eval date +"%m"`
YEAR=`eval date +"%Y"`
HOUR=`eval date +"%H"`
MINUTE=`eval date +"%M"`
PIMPURL=$BASEURL/$YEAR/$MONTH/$DAY/
COMMAND1="cd $PIMPURL"
$COMMAND1 2>/dev/null
if [ $? -eq 0 ]
then
echo "Command 1 was successful"
else
echo "There ain't folders!!"
echo "I'll mkdir some!"
COMMAND2="mkdir -p $PIMPURL"
$COMMAND2 2>/dev/null
fi
if [ $? -eq 0 ]
then
echo 'Command 1 or/and 2 was successful'
echo "STARTING MAIL BACKUP"
COMMAND3="tar -cvzf '"$PIMPURL"shisha_"$HOUR"_"$MINUTE"_.data.tar.gz' "$MAILURL
echo $COMMAND3
$COMMAND3 2>/dev/null
if [ $? -eq 0 ]
then
echo 'MAIL BACKUP SUCCESSFULL'
else
echo "FAILURE!!"
fi
else
echo 'Nope! Must be some kind of strage Err0r!!'
fi
So if I execute this script I get the following error:
Command 1 was successful
Command 1 or/and 2 was successful
STARTING MAIL BACKUP
tar -czvf '/mnt/alias/backup/2014/06/13/shisha_10_25_.data.tar.gz' /mnt/alias/storage/shishaMail
tar: Removing leading `/' from member names
tar (child): '/mnt/alias/backup/2014/06/13/shisha_10_25_.data.tar.gz': Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
FAILURE!!
As you see there is an echo of COMMAND3 which would be:
tar -czvf '/mnt/alias/backup/2014/06/13/shisha_10_21_.data.tar.gz' /mnt/alias/storage/shishaMail
And if I execute this command by hand, as the same user I execute the script as (which would be root in both cases), it works.
I don't get why the script complains about a not existing file or directory as the directories exist except the *.tar.gz file as this has to be created by tar.
/mnt/alias/backup/2014/06/13/exist? Also, what Richard said. How does the command behave differently when run manually?COMMAND3 echoand execute it manually, it works as assumed. @terdon yes i am sure/mnt/alias/backup/2014/06/13/exists. In fact, my script checks if it can switch the the repository. If he cannot, it will try to create the folder by themkdir -pcommand