Find the answer to your Linux question:
Results 1 to 4 of 4
hello,everyone! Just now I wrote a shell,Its role is to backup site and database, and then put them compressed package to my mailbox.Maybe I write wrong,In fact, I really wrong.But ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4

    Help me check the shell script..


    hello,everyone!

    Just now I wrote a shell,Its role is to backup site and database, and then put them compressed

    package to my mailbox.Maybe I write wrong,In fact, I really wrong.But I couldn't find the cause

    of the error occurs,I want to seek your help.If you know where is wrong, please tell me.thank you

    very much!

    This is the shell code:

    Code:
    #!/bin/sh
    
    #mysql username
    MYSQL_USER=root
    
    #mysql password
    MYSQL_PASS=578672331
    
    #e-mail address
    MAIL_TO=578672331'at'qq.com
    
    #database
    DB=xweb527
    
    #website the root directory
    WEB_DATA=/var/www/html
    
    #define database and website backup file name
    DataBacName=Data_$(date +"%Y%m%d").tar.gz
    WebBakName=Web_$(date +"%Y%m%d").tar.gz
    
    #delete the local data of three days ago
    rm -rf /root/backup/Data_$(date -d -3day +"%Y%m%d").tar.gz /root/backup/Web_$(date -d -3day +"%Y
    
    %m%d").tar.gz
    
    cd /root/backup
    
    #Export database, a database compressed into a file
    /usr/bin/mysqldump -u$MYSQL_USER -p$MYSQL_PASS ${DB} | gzip -9 - > ${DB}.sql.gz
    
    #Compressed database file for a file
    tar -zcpf /root/backup/$DataBacName /root/backup/*.sql.gz
    rm -rf /root/backup/*.sql.gz
    
    #Compression site data
    tar -zcpf /root/backup/$WebBakName $WEB_DATA
    
    
    #send email to me
    echo 'Theme: database and backup site' | mutt -s 'backup WEB527 site' -a /root/backup/
    
    $DataBakName -a /root/backup/$WebBakName  $MAIL_TO



    This is the error content:

    [root'at'localhost ~]# /bin/bash -x ./autoBackup.sh
    + MYSQL_USER=root
    + MYSQL_PASS=578672331
    + MAIL_TO=578672331atqq.com
    + DB=xweb527
    + WEB_DATA=/var/www/html
    ++ date +%Y%m%d
    + DataBacName=Data_20121020.tar.gz
    ++ date +%Y%m%d
    + WebBakName=Web_20121020.tar.gz
    ++ date -d -3day +%Y%m%d
    ++ date -d -3day +%Y%m%d
    + rm -rf /root/backup/Data_20121017.tar.gz /root/backup/Web_20121017.tar.gz
    + cd /root/backup
    + /usr/bin/mysqldump -uroot -p578672331 xweb527
    + gzip -9 -
    + tar -zcpf /root/backup/Data_20121020.tar.gz /root/backup/xweb527.sql.gz
    tar: Removing leading `/' from member names
    + rm -rf /root/backup/xweb527.sql.gz
    + tar -zcpf /root/backup/Web_20121020.tar.gz /var/www/html
    tar: Removing leading `/' from member names
    + echo 'Theme: database and backup site'
    + mutt -s 'backup WEB527 site' -a /root/backup/ -a /root/backup/Web_20121020.tar.gz
    578672331atqq.com
    /root/backup/ isn't a regular file.
    /root/backup/: unable to attach file.





    I checked/root/backup, compression package has been made:

    [root'at'localhost ~]# ls /root/backup
    Data_20121020.tar.gz Web_20121020.tar.gz

  2. #2
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,049
    Hi, and welcome to the forums!

    From how I read your script and the error it's causing, I think the problem is this:

    Code:
    echo 'Theme: database and backup site' | mutt -s 'backup WEB527 site' -a /root/backup/
    
    $DataBakName -a /root/backup/$WebBakName  $MAIL_TO
    Wich causes the error:
    Code:
    + echo 'Theme: database and backup site'
    + mutt -s 'backup WEB527 site' -a /root/backup/ -a /root/backup/Web_20121020.tar.gz
    578672331atqq.com
    /root/backup/ isn't a regular file.
    /root/backup/: unable to attach file.
    It's the newline between -a /root/backup/ and $DataBakName

    If that is the case, then I suppose:
    Code:
    echo	'Theme: database and backup site'	|\
    	mutt 	-s 'backup WEB527 site'		\
    		-a /root/backup/$DataBakName	\
    		-a /root/backup/$WebBakName	\
    	$MAIL_TO
    Should work
    Can't tell an OS by it's GUI

  3. #3
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4
    thanks,My problem has been solved

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,049
    Hey, that's good to hear
    Can't tell an OS by it's GUI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •