Results 1 to 4 of 4

Thread: Setup a Cronjob to backup a Crontab

  1. #1
    Join Date
    Apr 2009
    Location
    Saitama, Japan
    Beans
    132
    Distro
    Ubuntu 10.04 Lucid Lynx

    Setup a Cronjob to backup a Crontab

    I am trying to setup a cronjob to backup my crontab but it just creates an empty file. Here is what I input in my crontab -e.
    00 01 * * 0 /usr/bin/crontab -l > /media/store02/`/bin/hostname`_`/bin/date +\%Y-\%m-\%d`_crontab_bkup 2>&1

  2. #2
    Join Date
    Mar 2010
    Location
    Dublin, Ireland
    Beans
    Hidden!
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Setup a Cronjob to backup a Crontab

    That is strange. I've just tried adding the same command to my crontab and it works fine.

    The only thing I would suggest is to test if it creates the file properly if you specify your home directory, rather than something mounted through /media.

    Additionally you should see something like the following in syslog:

    Code:
    Feb  7 16:50:01 lechien-x CRON[28539]: (lechien) CMD (/usr/bin/crontab -l > /home/lechien/`/bin/hostname`_`/bin/date +%Y-%m-%d`_crontab_bkup 2>&1)
    Feb  7 16:50:01 lechien-x /usr/bin/crontab[28542]: (lechien) LIST (lechien)
    Matt
    blog.mattrudge.net for extra helpings of geeky Ubuntu goodness
    Get the Ubuntu Weekly Newsletter

  3. #3
    Join Date
    Apr 2009
    Location
    Saitama, Japan
    Beans
    132
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Setup a Cronjob to backup a Crontab

    You are correct in that it doesn't seem to work saving in a drive that is mounted. That was where I had it. This crontab was running for awhile now and I didn't bother to check the contain until recently. However, I did test it prior to using this code but I saved it in my primary drive thinking it would work on anywhere saved.

    How can I fix this since I do like it to save in an external drive incase my primary fails.

  4. #4
    Join Date
    Mar 2010
    Location
    Dublin, Ireland
    Beans
    Hidden!
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Setup a Cronjob to backup a Crontab

    If you check syslog after the cron job has run, it will likely give you a reason for the error.

    You could try directing the cron job to a subdirectory of /media/store02, which is set to 777 permissions.
    Matt
    blog.mattrudge.net for extra helpings of geeky Ubuntu goodness
    Get the Ubuntu Weekly Newsletter

Bookmarks

Posting Permissions

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