---
title: How to efficiently back up and restore crontab
description: How to efficiently back up and restore crontab when patching a database environment.
---

[Blog | Pythian ](https://www.pythian.com/blog)

# [How to efficiently back up and restore crontab](https://www.pythian.com/blog/how-to-efficiently-backup-and-restore-crontab)

 Written by [Michael Dinh](https://www.pythian.com/blog/author/michael-dinh) | Jul 27, 2018 4:00:00 AM

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.

## The Problem with Manual Crontab Management

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.

### Current Crontab State

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 
```

## A Better Way: Backup, Remove, and Restore

Instead of manual editing, we can export the entire table to a file and clear the crontab for the duration of the patching.

### 1. Backing Up the Crontab

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 
```

### 2. Clearing the Active Schedule

Remove crontab to ensure no jobs run during the patching window.

```
[oracle@racnode-dc1-1 ~]$ crontab -r; crontab -l  no crontab for oracle 
```

### 3. Restoring the Original Schedule

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 
```

## Efficiency for the "Lazy" Admin

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 ~]$ 
```

## Oracle Database Consulting Services

Ready to optimize your Oracle Database for the future?

[View full post](https://www.pythian.com/blog/how-to-efficiently-backup-and-restore-crontab)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Michael Dinh"
  },
  "dateModified" : "2026-03-14T21:09:31.763Z",
  "datePublished" : "2018-07-27T04:00:00Z",
  "headline" : "How to efficiently back up and restore crontab",
  "image" : {
    "@type" : "ImageObject",
    "height" : 60,
    "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
    "width" : 60
  },
  "mainEntityOfPage" : "https://www.pythian.com/blog/how-to-efficiently-backup-and-restore-crontab",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Pythian Blog"
  }
}
```