Backup system using cron

Since all backup plugins does not let me to choose specifc websites on my wpms to be backed up I did an sh script to be run through CRON, which is set in it as 0 0 * * 6 "script-path", as said at http://stackoverflow.com/questions/16717930/how-to-run-crontab-job-every-week-on-sunday
However it does not seem to be working, maybe because of the "zeros"? Any idea? Thank you!

  • Nastia

    Hello diegpl ,

    Hope you are doing well!

    This 0 0 * * 6 cron job should run, once a week at midnight each Saturday. The first zero means that the cron job will start at the beginning of the hour, and the second that it will start at 12:00 am, Midnight.

    Please let me know, if you set the cron job to run twice per minute, will the cron job be executed?
    Try this and make sure that the file you're pointing to has execute permissions:
    0,30 * * * * [script-path]

    Also, to find out if the cron running correctly, there should be cron.log files that might provide more information. The cron.log file position variates based on the server, please contact your host provider to find the location of this file.

    Hope this helps!

    Kind regards,
    Nastia

  • diegpl

    It seems that my sh script is working fine until the gdrive line:

    #!/bin/bash
    mkdir /home/xxx/public_html/xxxx &&
    .....
    gdrive upload -r /home/xxx/public_html/backupsgdrive &&
    rm -rf /home/xxxx/public_html/xxxx/

    When I run my .sh manually as the root user, the script works, everything is zipped to a folder then uploaded to Gdrive. However, when the script runs through cron tab it zips everything, but gets stuck on the gdrive upload command. Im guessing that through cron command it requests the root user, maybe. What do you think?
    If thats the case, do you think if I set it up on cron tab as:
    0 0 * * 3 crontab -u root /home/xxxx/xxxxx.sh

    Would that solve the problem? Thank you! :wink:

  • Nastia

    Hello diegpl

    My apologies for a late reply!

    Would you please let me know, have you deactivated WordPress wp-cron.php ? If not, please add the following line inside the wp-config.php file:
    define('DISABLE_WP_CRON', 'true');

    This will entirely disable built-in WP Cron. If you have added define( 'ALTERNATE_WP_CRON', true );, please remove this line.

    If a cron job is failing again, try replacing the path to:
    curl -I http://yoursite.com/wp-cron.php?doing_wp_cron

    Let me know if this change will upload files to a Google Drove destination.

    Kind regards,
    Nastia

  • diegpl

    Replace the path where? And why would I disable my wp_cron?
    Im working with a sh script. It runs out of any Wordpress function as I said here:
    #!/bin/bash
    mkdir /home/xxx/public_html/xxxx &&
    .....
    gdrive upload -r /home/xxx/public_html/backupsgdrive &&
    rm -rf /home/xxxx/public_html/xxxx/

    If I do what you are telling me I could break many things I have running over wp-cron with no reason to disable it, since the cron Im using is not related at all to wp-cron.

    Why do you think this cron can not solve the solution?
    0 0 * * 3 crontab -u root /home/xxxx/xxxxx.sh

    I though about that because when I run it while logged it works alright. What do you think about that solution? Do you imagine it could be something else? Do you know where I can see tle cron.logs on a cpnael server? And if you do not know what Im talking about, please, ask someone else to help me up here. My subscription ends on 3th and Im with this question here since 21th with no answer that makes sense yet.
    Thank you.

  • Sajid

    Hello diegpl,
    Hope you are doing good today :slight_smile:

    I am sorry for delay on this ticket and confusion. As you said the script works when you run it manually while logged in but does not while logged out with schedule. That means, there must be some authentication that is required to run this script.

    To find out why exactly it is not working, we have to look at syslogs or equivalent location. For example, /etc/syslog.conf, /var/log/cron, and /var/log/messages.

    You can find more details on following answer on stackexchange.
    http://unix.stackexchange.com/a/343

    Since it is directly related to your server, then I would suggest you contacting your hosting support as well since they are more well verse for handling such issues then support staff here.

    Take care and have a nice day :slight_smile:

    Best Regards,
    Sajid - WPMU DEV Support