• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Backup Crontabs of All Users on CentOS, RHEL, Ubuntu & Dabian

Written by Rahul, Updated on April 2, 2014

Crontabs are very useful in Linux for scheduling repeated jobs. We can schedule any script or command to run on particular time interval. All the jobs executed by cron runs in background. As a system admin, we know the importance of backups of system or application configuration files and we do it through cronjob but most of time to forget to take back of cronjobs.

This article will describe you to how to take backup of scheduled jobs for specific user or all users in system. To install or know more about Crontab refer our earlier articles.

How to Install Crontab in CentOS/RHEL 6/5
Crontab in Linux with 20 Useful Examples to Schedule Jobs

1. Backup Single User Cronjobs

Take the backup of scheduled jobs off current logged in user. This command will save all the output of current jobs listed in a txt file. From where we can simply restore it.

# crontab -l > cron-backup.txt

To backup jobs of other user in system, For example we are taking backup of all jobs scheduled for user john.

# crontab -u john -l > john-cron-backup.txt

2. Restore Single User Cronjobs from Backup

Cronjobs can be restored easily from backups as created above. Below is two commands which will restored jobs from backup created in above step.

# crontab cron-backup.txt
# crontab -u john john-cron-backup.txt

3. Backup All Users Cron jobs in CentOS/RHEL

All the cronjobs we scheduled for a user in CentOS/RHEL are physically stored in file with the username under /var/spool/cron directory. So to take backup of all jobs for all users, simply back /var/spool/cron directory.

# zip -r cronjobs-all.zip /var/spool/cron

We can also schedule this as job in crontab to take own backup

0 2 * * * zip -r cronjobs-all.zip /var/spool/cron

4. Backup All Users Cron jobs in Ubuntu and Debian

All the Cronjobs scheduled for a user in Ubuntu and Debian are physically stored in file with the username under /var/spool/cron/crontabs/ directory. So to take backup of all jobs for all users, simply create a backup of /var/spool/cron/crontabs directory.

# zip -r cronjobs-all.zip /var/spool/cron/crontabs

We can also schedule this as job in crontab to take own backup

0 1 * * * zip -r cronjobs-all.zip /var/spool/cron/crontabs

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy