When a database environment is being patched, entries from crontab are commented and then removed when patching is completed. The process works well when there are only a few entries from crontab, but it does not scale when crontab has dozens of entries and when some entries are commented and some are not. I believe a more efficient method is to backup and restore the existing crontab.
Managing crontab entries by commenting them out during maintenance is error-prone. It's difficult to track which jobs were originally active and which were intentionally disabled prior to the maintenance window.
Here is our starting point for the demo:
[oracle@racnode-dc1-1 ~]$ crontab -l */05 * * * * /bin/date > /tmp/date.out 2>&1 */15 * * * * /bin/date > /tmp/date.out 2>&1 #*/25 * * * * /bin/date > /tmp/date.out 2>&1 */35 * * * * /bin/date > /tmp/date.out 2>&1 */45 * * * * /bin/date > /tmp/date.out 2>&1 */55 * * * * /bin/date > /tmp/date.out 2>&1
Instead of manual editing, we can export the entire table to a file and clear the crontab for the duration of the patching.
Backup crontab and display contents. Extra precaution in case crontab.save.dinh is removed.
[oracle@racnode-dc1-1 ~]$ crontab -l > crontab.save.dinh; cat crontab.save.dinh */05 * * * * /bin/date > /tmp/date.out 2>&1 */15 * * * * /bin/date > /tmp/date.out 2>&1 #*/25 * * * * /bin/date > /tmp/date.out 2>&1 */35 * * * * /bin/date > /tmp/date.out 2>&1 */45 * * * * /bin/date > /tmp/date.out 2>&1 */55 * * * * /bin/date > /tmp/date.out 2>&1
Remove crontab to ensure no jobs run during the patching window.
[oracle@racnode-dc1-1 ~]$ crontab -r; crontab -l no crontab for oracle
Once maintenance is complete, restoring is a single-step process.
[oracle@racnode-dc1-1 ~]$ crontab crontab.save.dinh; crontab -l */05 * * * * /bin/date > /tmp/date.out 2>&1 */15 * * * * /bin/date > /tmp/date.out 2>&1 #*/25 * * * * /bin/date > /tmp/date.out 2>&1 */35 * * * * /bin/date > /tmp/date.out 2>&1 */45 * * * * /bin/date > /tmp/date.out 2>&1 */55 * * * * /bin/date > /tmp/date.out 2>&1
If you are lazy like me, then backup can be done in one command.
[oracle@racnode-dc1-1 ~]$ crontab -l > crontab.save.dinh; cat crontab.save.dinh; crontab -r; crontab -l */05 * * * * /bin/date > /tmp/date.out 2>&1 */15 * * * * /bin/date > /tmp/date.out 2>&1 #*/25 * * * * /bin/date > /tmp/date.out 2>&1 */35 * * * * /bin/date > /tmp/date.out 2>&1 */45 * * * * /bin/date > /tmp/date.out 2>&1 */55 * * * * /bin/date > /tmp/date.out 2>&1 no crontab for oracle [oracle@racnode-dc1-1 ~]$
Ready to optimize your Oracle Database for the future?