Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Commands»How to Backup Crontabs of All Users on CentOS, RHEL, Ubuntu & Dabian

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

    By RahulApril 2, 20142 Mins Read

    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.

    Advertisement

    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
    

    backup cron cronjobs crontab scheduler
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    free Command in Linux (Check Memory Uses)

    What are the difference between SH and BASH

    What are the difference between SH and BASH?

    Understanding the Zombie Processes in Linux

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Python Function with Parameters, Return and Data Types
    • free Command in Linux (Check Memory Uses)
    • Git Rebase: A Practical Guide
    • How to move the complete Git repository
    • Handling Special Characters in Shell Scripts
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.