Welcome to WebmasterWorld Guest from 54.196.243.192

Forum Moderators: bakedjake

Message Too Old, No Replies

Backup Script no Making New Directory

     
7:23 pm on Jul 14, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 27, 2005
posts:229
votes: 0


This is my backup shell script. I want it to create a backup directory and then put the backups in it. It doesn't seem to create the new directory.

----------------
#!/bin/sh
#backup website weekly

DATE=`date +%Y%m%d`

cd /var/www/vhosts/website.com/private/

mkdir $DATE-backups

cd

mysqldump --opt -uusername -ppassword dbname > /var/www/vhosts/website.com/private/$DATE-backups/backupsite-db-$DATE.sql

cd /var/www/vhosts/website.com/

tar -cvzf /var/www/vhosts/website.com/private/$DATE-backups/backupsite-backup-$DATE.tar httpdocs/

10:39 pm on July 14, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 28, 2003
posts:366
votes: 0


when you run this, try running it with:

sh -x nameofscript.sh

See what is causing the errors.

2:56 pm on July 15, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 27, 2005
posts:229
votes: 0


It looks like I have a lot of errors in my script. Why would this result in no file or directory found?

# sh -x backupscript.sh
++ date +%Y%m%d
+ DATE=20060715
+ cd $'/var/www/vhosts/website.com/private/\r'
: No such file or directory: /var/www/vhosts/website.com/private/
+ mkdir $'20060715\r-backups\r'
+ $'cd\r'
: command not foundne 7: cd

7:47 pm on July 15, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 27, 2005
posts:229
votes: 0


I'm using EditPlus to create the script. Then saving it as a utf-8 file. Then uploading it in ascii mode.
12:19 am on July 16, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 7, 2003
posts:505
votes: 0


Why would this result in no file or directory found?

Because of this:

+ cd $'/var/www/vhosts/website.com/private/\r'
: No such file or directory:

It's telling you that the directory you're trying to change in to doesn't exist. Since the change directory command fails, the make directory command makes the directory wherever you're running the script from.

1:33 am on July 16, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 1, 2002
posts:1421
votes: 0


\r is the problem. You wan to save it in unix format with bare LF's.

Also, ${DATE}-backups is the correct way to make sure the shell knows at which character the name of the variable ends.