LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell Script (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-229944/)

varunbihani 09-13-2004 02:39 AM

Shell Script
 
I AM TRYING TO WRITE FOLLOWING SHELL SCRIPT TO TAKE THE BACKUP OF MY DATABASE...

#!/bin/sh
mysqldump -uroot -p --opt <dbname> > /data/backup/DB_Backup/<file>.sql
cd /data/backup/DB_Backup/
tar -zcvf sqldata.tgz *.sql

THE DUMP NAME OF FILE THAT IS BEING CREATED IS <file>.sql? ..
I DONT UNDERSTAND WHY THIS LEADING "?" IS COMING..
I GET FOLLOWING ERROR...
I ALSO DONT UNDERSTAND WHY "NO SUCH FILE / DIRECTORY' ERRO IS COMING..

[root@console]# sh /data/test.sh
Enter password:
: No such file or directory/data/backup/DB_Backup/
tar: *.sql: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

mikshaw 09-13-2004 07:08 AM

if /data/backup/DB_Backup/ doesn't already exist, then your script won't work.
You should create that directory before running the script, or add something like this to the beginning of the script:

backup_dir=/data/backup/DB_Backup
if [ ! -d "$backup_dir" ]; then
mkdir -p "$backup_dir"
fi

mikshaw 09-13-2004 07:08 AM

double-dose... :eek:

varunbihani 09-13-2004 10:32 AM

data/backup/DB_Backup
 
data/backup/DB_Backup
already created!!!
but still the same error

chrism01 09-13-2004 11:31 AM

check the ownerships/permissions on that dir. The backup script must be able to see/write to it.

mikshaw 09-13-2004 05:00 PM

it's apparently being run as root, so permissions shouldn't be a problem.

in the script you said the directory was /data/backup/DB_Backup (note the first slash)
and in your more recent post you said data/backup/DB_Backup already created. Is this a typo, or are you talking about two different paths? The second one would be a subdirectory of the current working directory...the first one is a full path starting at root.


All times are GMT -5. The time now is 08:53 PM.