Final answer:
To backup Alice's home directory on Linux, a shell script is used to create and compress a tar archive file before moving it to /var/backups. A cron job can be set up to run this script every 3 minutes, which can be later canceled by editing the crontab.
Step-by-step explanation:
The process of backing up a user's home directory in Linux involves creating a tar archive file and then compressing it for efficient storage. Below is a shell script that performs the backup operation following the steps you have outlined:
#!/bin/bash
# Input MIDAS name and current date
read -p "Enter your MIDAS name: " midas
read -p "Enter current date (YYYY.MM.DD): " date
# Create a filename variable
filename="${midas}-${date}"
echo "Creating backup for Alice's home directory..."
# Create a tar file of Alice's home directory
tar -cvf "/var/backups/${filename}.tar" /home/Alice
echo "Backup file created: ${filename}.tar"
# Move the backup file to the /var/backups/ directory
# mv "/var/backups/${filename}.tar" /var/backups/ # This command is redundant as we're already creating tar in the /var/backups
echo "File moved to /var/backups/"
# Compress the tar file using gzip
gzip "/var/backups/${filename}.tar"
# Confirm file compression
ls -lh "/var/backups/${filename}.tar.gz"
# Schedule the backup to run every 3 minutes using crontab (add this line to crontab)
# */3 * * * * /path/to/backup_script.sh
# After confirming file in /var/backups, disable the cron job by commenting out or deleting the line from crontab
To schedule the backup task to run every 3 minutes, you will need to add the appropriate cron job. You can do this by running 'crontab -e' and entering the line as indicated in the script comments. Afterwards, to view the contents of the /var/backups directory, you can use the 'ls' command. To cancel the crontab jobs, you will need to edit the crontab again and either comment out or delete the line for the job.
Please remember to grant the script executable permissions using 'chmod +x scriptname.sh', replace 'scriptname.sh' with the name of your script. Additionally, before performing any of the above operations, you should have the appropriate permissions or use the 'sudo' command if needed.