Welcome to WebmasterWorld Guest from 54.205.130.92

Forum Moderators: bakedjake

Backup Script no Making New Directory

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

10+ Year Member



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 Jul 14, 2006 (gmt 0)

10+ Year Member



when you run this, try running it with:

sh -x nameofscript.sh

See what is causing the errors.

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

10+ Year Member



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 Jul 15, 2006 (gmt 0)

10+ Year Member



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 Jul 16, 2006 (gmt 0)

10+ Year Member



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 Jul 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



\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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month