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/
- #!/bin/bash
- This script changes to the
backup
directory, creates a compressed tar archive of thevital_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/
- #!/bin/bash