backup cron help needed

Discussion in 'Server Operation' started by bswinnerton, Mar 6, 2010.

  1. bswinnerton

    bswinnerton New Member

    Hey everyone,

    I've been trying to code up a backup script that tar's up my server every morning and sends it to an nfs share I have on my windows box. How can I throw it into a cron but keep the date in the log file that it creates?

    Here's what I have, but it comes up with an error in the root mail:

    Code:
    0 3 * * * /bin/backup 2>&1 >> /var/log/backup_`date '+%m%d%y'`
    and the error:

    Code:
    Message 1:
    From [email protected]  Fri Mar  5 03:00:02 2010
    X-Original-To: root
    From: [email protected] (Cron Daemon)
    To: [email protected]
    Subject: Cron <[email protected]> /bin/backup 2>&1 /var/log/backup_`date '+
    Content-Type: text/plain; charset=ANSI_X3.4-1968
    X-Cron-Env: <SHELL=/bin/sh>
    X-Cron-Env: <HOME=/root>
    X-Cron-Env: <PATH=/usr/bin:/bin>
    X-Cron-Env: <LOGNAME=root>
    Date: Fri,  5 Mar 2010 03:00:01 -0500 (EST)
    
    /bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
    /bin/sh: -c: line 1: syntax error: unexpected end of file
    
    and my code:

    Code:
    #!/bin/bash
    filename=`date '+%m%d%y'`_file_backup
    
    cd /
    umount /mnt/data
    mount -t nfs 192.168.1.1:/Data /mnt/data
    mkdir -p /mnt/data/`date '+%m%d%y'`
    mysqldump --add-drop-table --user criticalwire --password=password mysite > /mnt/data/`date '+%d%m%y'`/`date '+%d%m%y'`_sql_backup.sql
    tar -cPzf /mnt/data/`date '+%m%d%y'`/$filename.tgz --exclude=/proc --exclude=/lost+found --exclude=/mnt/data/=`date '+%m%d%y'`/filename.tgz --exclude=/mnt --exclude=/sys --exclude=/var/run --exclude=/var/spool/postfix --exclude=/dev/log --exclude=/var/lib/named/dev/log --exclude=/var/log/backup/backup_`date '+%d%m%y'`.log / /mnt/data/`date '+%m%d%y'`/sql_backup_`date '+%d%m%y'`.sql
    find /mnt/data/* -mtime +7 -exec rm -Rf {} \;
    find /var/log/backup/backup_*.log -mtime +7 -exec rm -Rf {} \;
    cp /var/log/backup/backup_`date '+%m%d%y'`.log /mnt/data/`date '+%m%d%y'`/`date '+%m%d%y'`_log.log
    
     
  2. falko

    falko Super Moderator ISPConfig Developer

    I think that cron cannot interpret `date '+%m%d%y'`. This should better go directly into your backup script, i.e., there should be code in your backup script that creates the log file so that you can remove the >> /var/log/backup_`date '+%m%d%y'` part from cron.
     

Share This Page