cron 2

Savanna is a RHEL Syadmin at IBM. Her supervisor tell her the write a script to backup /home/savanna/vital_docs to /home/savanna/backup.tar.gz each Sunday at 2:30 AM. Show all the commands that she will issue and the text of the script.

  • Create a new directory called backup in /home/savanna.
    • mkdir /home/savanna/backup
  • Change the ownership and permissions of the backup directory to ensure that Savanna has write access.
    • chown savanna:savanna /home/savanna/backup
    • chmod 700 /home/savanna/backup
  • Create a new script file called backup_script.sh in /home/savanna and add the following code:
    • #!/bin/bash

      # Move to the backup directory
      cd /home/savanna/backup

      # Create a tar archive of the vital_docs directory
      tar -czf backup.tar.gz /home/savanna/vital_docs

      # Move the backup file to the home directory
      mv backup.tar.gz /home/savanna/
  • This script changes to the backup directory, creates a compressed tar archive of the vital_docs directory, and then moves the resulting backup file to the home directory.
  • Make the script executable.
    • chmod +x /home/savanna/backup_script.sh
  • Set up a new cron job to run the script each Sunday at 2:30 AM. To do this, run the following command:
    • crontab -e
  • Add the following line to the end of the crontab file:
    • 30 2 * * 0 /home/savanna/backup_script.sh
    • This cron job will run the backup_script.sh file every Sunday at 2:30 AM.
  • Overall, the commands that Savanna will need to issue are:
    • mkdir /home/savanna/backup
    • chown savanna:savanna /home/savanna/backup
    • chmod 700 /home/savanna/backup
    • nano /home/savanna/backup_script.sh
    • chmod +x /home/savanna/backup_script.sh
    • crontab -e
  • And the text of the script is:
    • #!/bin/bash

      # Move to the backup directory
      cd /home/savanna/backup

      # Create a tar archive of the vital_docs directory
      tar -czf backup.tar.gz /home/savanna/vital_docs

      # Move the backup file to the home directory
      mv backup.tar.gz /home/savanna/

 

 

  •  
You should also read:

crontab and cron

Bird is a RHEL Sysadmin at Google, a really good one. He is teaching two new hires about cron and crontab. He wants…

cron and crontab

Charlier "Bird" Parker is a genius-level saxophonist who has memorized every Linux command in about 2 hours. After a 10 minute interview at…

/var/log/cron

Sonny Stitt is a phenomenal alto saxophonist by night, and a RHEL Systems Manager at Red Hat (Chicago campus) by day. His teams…

cron

Delta is a RHEL Sysadmin at IBM. She has written a script called backup.sh. She wants to create a cron job to run…