+ Reply to Thread
Results 1 to 3 of 3

Thread: Crontab

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    2

    Default Crontab

    I haven't used crontab before so I may be making a simple mistake.

    I'm trying to set up a cron that backs up a folder every day. For testing purposes I've just set it to run every hour on a particular minute.

    (MYUSERNAME is my account name, I know I have that correct)

    My home directory is: /hsphere/local/home/MYUSERNAME
    I created the folder backups so that location is: /hsphere/local/home/MYUSERNAME/backups/

    So in crontab, under H-sphere, I set:
    Minute: 0
    Hour: *
    Day of Month: *
    Month: *
    Day of Week: *

    Command:
    Code:
    tar -czf /hsphere/local/home/MYUSERNAME/backups/$(date +%Y%m%d)web-backup.tgz /hsphere/local/home/MYUSERNAME/container.MYDOMAIN.net/wp-content/
    I got that command from someone else, so maybe there is a problem with that?

    Any help appreciated!

  2. #2
    Member
    Join Date
    Jan 2008
    Posts
    36

    Default

    What you have will run every hour (each time that minute=0). You need to also set hour to something (like 0).

    I'm also not clear if you have the file actually formatted correctly or not as what you have there is not the file format.

    This is what a line looks like:

    55 3 * * * rm a.file

    This will run "rm a.file" every day at 3:55am. Each command is on a separate line, and each one starts with the time/day that it should run.

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    2

    Default

    Ok I just tried the following code and it worked! So it must be the date part that is off:

    Code:
    tar -cWPpf /hsphere/local/home/MYUSERNAME/backups/web-backup.tar.gz /hsphere/local/home/MYUSERNAME/container.MYDOMAIN.net/wp-content/
    EDIT: I did a bit more research and messing around and found that the % sign is interpreted as a new line unless you escape it with a backslash. So this now works:

    Code:
    tar -cWPpf /hsphere/local/home/MYUSERNAME/backups/$(date +\%Y\%m\%d).web-backup.tar.gz /hsphere/local/home/MYUSERNAME/container.MYDOMAIN.net/wp-content/
    Last edited by atricity; 06-16-2009 at 10:50 PM.

+ Reply to Thread

Posting Permissions

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