Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    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

    RahulBy 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.

    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
    Previous ArticleHow to Setup MariaDB Galera Cluster 5.5 in CentOS, RHEL & Fedora
    Next Article S3cmd – Sync Files Between S3 bucket and Local Directory

    Related Posts

    (Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms

    Updated:May 10, 20221 Min Read

    How to Install Apache ActiveMQ on Ubuntu 22.04

    3 Mins Read

    How To Enable SSH Server on Ubuntu 22.04

    Updated:April 22, 20222 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    How to Backup Website to Amazon S3 using Shell Script

    Updated:March 24, 20222 Mins Read

    How to Search Recently Modified Files in Linux

    2 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Sublime Text 4 on Ubuntu 22.04
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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