Step 5: Create a Cron Job ========================= .. include:: /includes/prolog.inc .. include:: urls.rst .. contents:: Table of Contents **Objective**: Create a ``cron job`` for your backup script. Now that you have a simple backup script, you want to run it periodically to ensure that your data is copied to another part of your VPS to keep it safe from accidental deletion. Use |A Beginners Guide To Cron Jobs| and |Creating a custom Cron Job| to help you. Build a Daily Cron Job ---------------------- You will use the ``crontab`` application to install, remove, or edit cron jobs. #. Edit the cron jobs. #. Choose a time to run the script. * You should perform the backup when the system has low usage, such as when most of your users sleep. * Pick a time between 02:00 to 05:00. #. Build your cron job. This example runs at 03:00 daily. .. code-block:: bash 0 3 * * * #. List the cron jobs to verify that they were installed correctly. .. code-block:: bash crontab -l Testing your Cron Job --------------------- It is not easy to test cron jobs that run infrequently. You need to know two things: |br| **(1)** Did it run, and **(2)** did it run correctly. * You can run a cron job manually using Webmin: |br| *Webmin* -> *System* -> *Scheduled Cron Jobs* * The output will display to the browser. Another method is to log the output data to a file instead of to the screen. You can use this information to determine if it ran and if it produced expected data. * You can configure a command to send |standard output| (stdout) results to a file instead of the screen using ``> output-file``: .. code-block:: bash command > /path/to/output.txt .. code-block:: bash :caption: Examples # shell commands ls -lh > dir-listing.txt ./backup-docker.sh > /tmp/output.txt # from a cron job 0 3 * * * bash /root/backup-user-data.sh > /var/user-backups/backup-log.txt