Recover a crontab by locating the backed-up spool file that stores it, restoring that file to the correct per-user path with the right ownership and mode, then reloading and verifying the schedule. On most Unix systems each user's crontab lives under /var/spool/cron or /var/spool/cron/crontabs, saved as a plain text file named after the account. Getting it back is mostly about finding the right copy, putting it where the cron daemon expects it, and confirming it actually loaded. The hard part is rarely the file copy itself; it's knowing which backup you have, who owned the job, and whether the daemon in front of you reads from that path at all.
This guide assumes you already have some backup that may contain the crontab: a full filesystem archive, a database-style dump, a configuration management export, or a manual copy. I'll walk through identifying what you have, restoring it safely on the main cron implementations (Vixie cron on Linux and BSD, and the Solaris-style layout), validating syntax, and fixing the mistakes that make a restored crontab silently do nothing.
First, identify which cron implementation and spool path you're dealing with
There is no single standard location for crontab spool files. The path depends on the cron daemon and the OS flavor. Before you copy anything, determine what runs on the target machine and where it stores user crontabs.
| Environment | Typical user crontab path | Typical system crontab path | Notes |
|---|---|---|---|
| Debian/Ubuntu (Vixie cron, and cronie on some derivatives) | /var/spool/cron/crontabs/ | /etc/crontab, /etc/cron.d/ | Spool directory is mode 1730; files are typically mode 600 |
| RHEL/CentOS/Fedora and cronie-based systems | /var/spool/cron/ | /etc/crontab, /etc/cron.d/ | Selinux contexts can matter when restoring |
| FreeBSD and many BSDs | /var/cron/tabs/ | /etc/crontab | Owner is usually root with group wheel or cron |
| Solaris/illumos | /var/spool/cron/crontabs/ | /etc/crontab, /etc/cron.d/ | Files are owned by the user, group cron, mode 600 |
| macOS | /usr/lib/cron/tabs/ (legacy) or managed via launchd | /etc/crontab | Modern macOS deprecates cron in favor of launchd |
Check the running daemon first. ps -ef | grep -i cron shows whether you have cron, crond, cronie, or something else. On many Linux systems, systemctl status cron (Debian-family) or systemctl status crond (RHEL-family) confirms the unit name. The unit file often reveals the spool path with a line such as -f or a CRON_SPOOL_DIR setting in /etc/sysconfig/crond or /etc/default/cron. Reading /etc/default/cron on Debian-family systems is worth one minute because it can set -c or affect which spool directory is used.
If you're restoring onto a rebuilt machine that may differ from the original, cross-check the backup's OS release notes. Copying a Debian spool file to the right place on a Debian box is trivial; copying it into a path the daemon doesn't read is a common way to spend an afternoon debugging a schedule that never fires.
What a crontab backup actually looks like
A user crontab backup is almost always a small text file: five time fields, then the command. Environment assignments can appear at the top, such as SHELL=/bin/bash, PATH=/usr/local/bin:/usr/bin:/bin, [email protected], or HOME=/home/app. Comments start with #.
That matters because there are several kinds of "backup" and they aren't interchangeable:
Spool file copy: a literal copy of /var/spool/cron/crontabs/alice or /var/spool/cron/alice. This is the cleanest form to restore; it's already in the daemon's native format. Export via crontab -l: the output of crontab -l > alice.cron as that user. Functionally identical in content, and usually the safest to re-import because it's canonicalized. Database or application-level dump: some schedulers (Jenkins, rundeck, Airflow, custom apps) store schedules in a database. If your "crontab" was generated from a config repo, restoring the repo entry and re-deploying is better than hand-placing a spool file. Filesystem image or snapshot: you'll need to mount or extract it and find the file inside. A tarball backup of /etc alone won't include the spool directory, which is one of the most common reasons a restore "can't find" the crontab. Configuration management: if the crontab was deployed by Ansible, Puppet, Chef, or Salt, the true source of truth is the repo. Restoring the spool file directly will be overwritten on the next run, so restore the manifest instead.
A quick sanity check on content: a valid entry looks like 30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1. If your backup contains @reboot, @daily, or other shorthand macros, confirm the target daemon supports them; Vixie/cronie and most modern implementations do, but some minimal embedded cron daemons don't.
Locate the specific backup copy and confirm it's the right one
Before restoring, find the most recent plausible copy and verify its contents. This is the step people skip, and it causes restores of stale schedules.
1: Search your archive for the filename. For a tarball: tar -tzf backup.tar.gz | grep -E 'cron(tab|tabs)?/(alice|root)'. For an rsync-style tree, find /backup -path 'cron' -name alice. For a filesystem image, mount it read-only and look under the paths in the table above. 2: Compare timestamps and job content. A backup from three months ago may miss jobs added since. Compare the restored entry list against what you expect: service names, log paths, notification recipients. 3: Check for line-ending and encoding damage. Files that passed through Windows tooling can pick up CRLF endings. file alice.cron and cat -A alice.cron | head reveal stray ^M. Strip them with sed -i 's/\r$//' alice.cron before installing. 4: Watch for truncated files. A backup interrupted mid-write can leave a spool file with a partial last line. A crontab whose final line is cut off may fail to parse or, worse, silently drop the last job. Inspect the tail. 5: Confirm the owning account still exists. If the original user was removed, restoring their spool file does nothing useful; the jobs will not run. Decide whether to recreate the account, reassign the jobs to another user, or move them to a system crontab.
It's also worth asking whether the backup captured the spool directory at all. Many backup policies exclude /var/spool as volatile data. If yours did, look for crontab -l exports in configuration repos, in /root home directories, or in monitoring systems that may have cached the schedule.
Restore the spool file the safe way
The safest general method is to install the contents through the crontab command rather than copying files directly, because the command handles ownership, permissions, and validation. Direct file copies are sometimes necessary, especially on Solaris or when the account can't log in, but prefer the command when you can.
Prerequisites: root or sudo access on the target, the backup file readable, and the target user account present. Know the target daemon's spool path from the first section.
1: Stage the file in a temp location owned by root with mode 600, e.g. /root/alice.cron.restore. Don't leave it world-readable; crontabs often contain credentials or internal hostnames in commands. 2: Normalize formatting: strip CRLF, ensure a trailing newline (printf '\n' >> file if missing), and remove any lines the daemon can't parse. 3: Dry-run the content mentally or with a linter. Some distributions ship crontab -T (cronie) to test a file without installing; if available, run crontab -T /root/alice.cron.restore. 4: Install as the owning user. As root: crontab -u alice /root/alice.cron.restore. This replaces alice's entire crontab. On Solaris, the equivalent is crontab -u alice /root/alice.cron.restore as root, which writes into /var/spool/cron/crontabs/alice. 5: If direct copy is unavoidable, place the file at the daemon's spool path, then set ownership and mode. On Debian-family: chown alice:crontab /var/spool/cron/crontabs/alice and chmod 600. On RHEL-family with cronie: chown alice:alice /var/spool/cron/alice and chmod 600. On BSD: chown root:wheel /var/cron/tabs/alice and chmod 600. On Solaris: chown alice:cron /var/spool/cron/crontabs/alice and chmod 600. Spool directories themselves should be mode 1730 (sticky, group-execute, no group-write for others) on Debian-family systems; don't loosen them to make a copy work. 6: Reload or restart the daemon if your implementation caches. Most Vixie/cronie daemons re-scan the spool directory, but a restart removes doubt: systemctl restart cron or systemctl restart crond, or /etc/init.d/cron restart on older systems. 7: Verify as the user. Run crontab -l -u alice (as root) or crontab -l (as alice) and confirm the output matches the backup.
Success check: the listing shows every expected line in the expected order, and ls -l on the spool path shows the correct owner, group, and -rw-------. If crontab -l errors, the file failed a validation or permission check; fix the cause rather than forcing a copy.
Failure modes to watch: crontab: usage error: file name must be specified for replace usually means you passed arguments in the wrong order; crontab: cannot open /var/spool/cron/crontabs/alice: Permission denied points to ownership or mode; crontab: temp file must be edited in place is a quirk of some editors and doesn't apply when installing from a file. If the entry appears in crontab -l but never runs, the problem is usually the environment (PATH, shell) or the command path, not the restore.
Check system crontabs, which aren't recovered with crontab -l
User spool files are only part of the schedule. System-level entries live in /etc/crontab, files under /etc/cron.d/, and drop-ins under /etc/cron.daily, /etc/cron.hourly, /etc/cron.weekly, and /etc/cron.monthly on Debian-family systems (RHEL-family uses /etc/cron.d plus /etc/anacrontab for some jobs). The crontab command does not list these, so a restore that only addresses user spools can leave root's system jobs missing.
Restore them by copying from the backup into place with root ownership and mode 644 for /etc/crontab and /etc/cron.d/. Those files have an extra field: /etc/crontab lines include the user to run as ( * * * * root /usr/local/bin/task), whereas user spool files don't. Mixing the formats is a classic restore error: pasting a system-format line into a user crontab makes the daemon treat the username as the start of the command.
For Debian-family systems, /etc/cron.d files are read by the daemon, while /etc/cron.daily and friends are run by run-parts from entries in /etc/crontab or /etc/anacrontab; if you restore the drop-ins but forget the scheduling entry that invokes run-parts, those scripts won't run. On RHEL-family, anacron covers jobs that may have been missed while the machine was off; restoring /etc/anacrontab and any /etc/cron.d files together keeps that behavior intact. On Solaris and illumos, the root crontab is in /var/spool/cron/crontabs/root, and there's also /etc/cron.d support on newer releases; check which exists before assuming.
Validate the recovered schedule before trusting it
A restored file that parses isn't necessarily a working schedule. Validation has three layers: syntax, environment, and behavior.
Syntax. Time fields must be within range (minute 0-59, hour 0-23, day of month 1-31, month 1-12, day of week 0-7 with both 0 and 7 as Sunday on most implementations). Ranges, steps, lists, and names are accepted (MON-FRI, */15, 1,15). Comments and blank lines are fine. Be careful with % characters in commands: in cron they're converted to newlines unless escaped as %, so a password containing % needs escaping. Macro entries (@daily, @reboot) are supported by cronie and Vixie but confirm on the target.
Environment. Cron runs with a minimal environment. If the original jobs relied on a PATH set by the user's shell profile, they may have worked interactively and failed under cron even before the backup. The original spool file likely had explicit PATH= and SHELL= lines for that reason; don't drop them during cleanup. If the backup was truncated and lost those lines, add them back deliberately. A job that ran manually and fails under cron almost always means path, shell, or user mismatch.
Behavior. Set the minute field to the next minute for one benign job and watch the log. Confirm the command runs as the intended user (ps -o user,cmd during the run, or check a log file's ownership). If output goes to mail, confirm MAILTO still points to a monitored address; silent failures often live in unread root mail. Then restore the original schedule.
Handle permissions, ownership, and SELinux or mandatory-access controls
Every cron implementation enforces that the spool file is owned by the user it describes, or by root, with restrictive permissions. Getting this wrong produces the same symptom: the schedule appears (or doesn't) and jobs never run.
Debian-family: spool files are user-owned, group crontab, mode 600, inside a directory mode 1730. If you see a file owned by root in a user spool slot, either the daemon refuses to use it or the jobs run as the wrong user. Fix ownership rather than widening mode. RHEL-family (cronie): spool files are user-owned, mode 600. SELinux may label restored files incorrectly if you copy them with tools that preserve only Unix metadata. After a direct copy, run restorecon -v /var/spool/cron/ to apply the expected security context. On an enforcing system with a wrong label, crontab -l may work while execution is denied; ausearch -m avc -ts recent shows relevant denials. BSD: spool files under /var/cron/tabs are owned by root, group wheel or cron, mode 600, and the directory is tightly restricted. Copying a user-owned file there can cause it to be ignored. Solaris/illumos: files are user-owned, group cron, mode 600, and the spool directory has specific permissions. crontab -u user file as root is the least error-prone path. AppArmor or other MAC frameworks on some distributions restrict which paths cron may read; if the daemon was confined and the restored path differs from the profile, check the audit log.
A useful diagnostic: run crontab -l as the owner. If that succeeds but jobs don't run, permissions on the spool file are probably fine and the problem is elsewhere. If crontab -l itself fails with a permission error, the spool metadata is wrong and should be fixed before anything else. Many daemons also write to syslog on every reload; journalctl -u cron -n 50 or /var/log/cron (RHEL-family) and /var/log/syslog (Debian-family) show whether a file was rejected.
Know when to stop and involve someone else
Restoring to a single machine you administer is low-risk. Some situations call for a second person or the platform owner:
The target is a shared or production system with compliance controls, and the crontab can trigger payments, deletions, or customer-facing jobs. The backup frequency, retention, or integrity status is unknown and you can't confirm whether other copies exist. The cron daemon is part of a managed scheduler (systemd timers, Kubernetes CronJobs, cloud functions) and the "crontab" you found is really a generated artifact; editing the generated copy will be overwritten by the controller. SELinux or mandatory-access denials remain after a restorecon, which suggests a policy change you shouldn't guess at.
In those cases, stop at the verification stage: prepare the restored file, document the expected entries, and get the change reviewed through whatever process the environment uses. The mechanics are straightforward; the consequences of an unexpected job are what argue for caution.
A short worked example
Suppose a Debian server has been rebuilt and its /etc was preserved in a backup. The app account's crontab needs restoring, and the archive is /backup/etc-only.tar.gz. Because /var/spool wasn't in that backup, the spool file is missing, but crontab -l output was saved to /root/crontabs/app.cron on the old host inside a configuration directory that was included.
1: Extract and inspect: tar -tzf /backup/etc-only.tar.gz | grep -i cron shows no spool file but does show ./opt/ops/crontabs/app.cron. 2: Compare with the service documentation to confirm the expected jobs, because the export could be stale. 3: Copy the file to /root/app.cron.restore, strip CRLF, and check the tail for truncation. 4: Install: crontab -u app /root/app.cron.restore. 5: Verify: crontab -l -u app lists four jobs, including a PATH= line at the top. ls -l /var/spool/cron/crontabs/app shows -rw------- 1 app crontab. 6: Test one job by temporarily changing its minute field, installing again, and watching /var/log/syslog for the daemon's run entry. 7: Restore the original timing and remove the staged file.
If the verification listing shows the four jobs but a run still doesn't appear in the log, the next check is the command path and the user's ability to read its script and log files, not the cron installation itself.
Frequently asked questions
Can I recover a crontab after the spool file is gone? Only from another copy: a crontab -l export, a configuration repository, a filesystem snapshot, or a filesystem image. The daemon holds the schedule in memory, but there is no supported command to write it back out after a restart, so grabbing a crontab -l export from the running system before maintenance is the reliable fallback.
Why does the restored crontab show up but never run? The most common causes, in rough order, are a missing PATH or SHELL line, a command referring to a binary or script that isn't at that path on the new host, wrong ownership or mode on the spool file, a SELinux label mismatch after a direct copy, and a daemon that hasn't rescanned the spool directory. Check crontab -l as the user, then the daemon log, then the command path.
Should I restore the spool file directly or use crontab? Use crontab -u user file whenever the account exists and you have root or sudo. It handles ownership, permissions, and format checks. Direct copies are the fallback for systems where the user can't log in or for implementations where the command behaves unexpectedly, and they require manual metadata cleanup.
Does the backup include root's crontab? Only if your backup captured /var/spool/cron/crontabs/root or /var/spool/cron/root (or /var/cron/tabs/root on BSD) and /etc/crontab and /etc/cron.d. Root's user crontab is a spool file like any other and is often missed because backup policies treat /var/spool as volatile.
What if the original machine used systemd timers instead of cron? Then there is no crontab spool file to restore. Look for unit files under /etc/systemd/system/*.timer and *.service, plus systemctl list-timers output saved in backup notes. Restoring a timer requires copying both the timer and service units, then systemctl daemon-reload and enabling the timer, which is a different procedure from crontab recovery.