Page tree
Skip to end of metadata
Go to start of metadata

Crontab is used in Linux distributions to schedule jobs.  It can be scheduled for specific minute(s), hour(s), day(s), and so forth.  More information can be seen here. The Wikipedia article explains it fairly well also. For more information on the SSDT Supplied Scripts, see this page.

Crontab Basics

Look at existing crontab

## to look at an existing crontab file
sudo crontab -l

Edit existing crontab

##to edit/create a crontab file (use sudo to make it for root)
sudo crontab -e

##add any commands

Updating SSDT images

Pulling and applying ssdt supplied images on a daily basis is recommended.  On Ubuntu, crontab is used for this. First, update the ssdt utilities package, pull the image updates, and then apply the updates. See here for specific information on applying software updates. 

These daily updates can be logged.  The > syntax overwrites any exiting logfile with the same fully qualified name, and >> appends to any existing logfile with the same fully qualified name (and it will create one if none exists).

A date can be added to the log file name.  Note when adding a date, use ` (it is generally on the ~ key) and not '. 

In the following example, jobs are scheduled on a daily basis (as the root user)  to update the ssdt utilities at 1:00 a.m., updated images are pulled at 1:10 a.m., updates to the /data/prod directory tree are applied at 1:30 a.m. Also, the results of each job is written to a logfile as specified.

##to overwrite exiting logfiles, entries should be:
0 1 * * *   /ssdt/ 2>&1 > /data/prod/update-utilities.log
10 1 * * *   /ssdt/scripts/ 2>&1 > /data/prod/updates-pull.log
30 1 * * *  /ssdt/scripts/ /data/prod 2>&1 > /data/prod/updates-apply.log

##to append to exiting logfiles (and create a new one if none exists), entries should be:
0 1 * * *   /ssdt/ 2>&1 >> /data/prod/update-utilities.log
10 1 * * *   /ssdt/scripts/ 2>&1 >> /data/orid/updates-pull.log
30 1 * * *  /ssdt/scripts/ /data/prod 2>&1 >> /data/prod/updates-apply.log

##Example creating logfiles with specific dates
##update utilities at 1:00 a.m. and write to /data/prod/update-utilities-year-month-day-hour:minute.log (adds a date to the logfile name)
##example logfile name with this command:  update-utilities-2017-09-27-01:00.log
0 1 * * *   /ssdt/ 2>&1 > /data/prod/update-utilities-`date +\%Y-\%m-\%d-\%H:\%M`.log

If desired, a job could be added to cleanup any unused ssdt images by adding the following line (in this example, unused images are cleaned up at 2:00 every Saturday).  The log is overwritten.  You could add a date to the logfile name as in the above examples.

0 2 * * 6   /ssdt/scripts/ 2>&1 > /data/prod/updates-cleanup.log

Automating Backups

USXS backup basics are described here.  In order to automate these backups, the script must be used along with the script.

## backup usps databases for running containers in the /data/prod directory tree at 1:40 and append to the log file
## backup usas databases for running containers in the /data/prod directory tree at 1:45 and append to the log file
40 1 * * *  /ssdt/scripts/ /data/prod /ssdt/scripts/ 2>&1 >> /data/prod/backup-usps.log
45 1 * * *  /ssdt/scripts/ /data/prod /ssdt/scripts/ 2>&1 >> /data/prod/backup-usas.log

Example of a full cron job

In this job, utilities updates are pulled daily at 1:00 a.m. Available release updates are pulled at 1:10 a.m. and applied at 1:30 a.m.  At 1:40 a.m., all usas databases for instances running in /data/prod directory tree are backed up, and the usps ones are backed up at 1:45 a.m.  Image cleanup is performed every Saturday at 2:00 a.m.  With the exception of the cleanup log, dates are placed in the name of the logs.

0 1 * * *   /ssdt/  2>&1 >> /data/prod/update-utilities-`date +\%Y-\%m-\%d-\%H:\%M`.log
10 1 * * *   /ssdt/scripts/ 2>&1 >> /data/prod/updates-pull-`date +\%Y-\%m-\%d-\%H:\%M`.log
30 1 * * *  /ssdt/scripts/ /data/prod 2>&1 >> /data/prod/updates-apply-`date +\%Y-\%m-\%d-\%H:\%M`.log
40 1 * * *  /ssdt/scripts/ /data/prod /ssdt/scripts/ 2>&1 >> /data/prod/backup-usps-`date +\%Y-\%m-\%d-\%H:\%M`.log
45 1 * * *  /ssdt/scripts/ /data/prod /ssdt/scripts/ 2>&1 >> /data/prod/backup-usas-`date +\%Y-\%m-\%d-\%H:\%M`.log
0 2 * * 6   /ssdt/scripts/ 2>&1 > /data/prod/updates-cleanup.log
  • No labels