Challenge - 5 Problems
Backup Automation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this backup script snippet?
Consider this bash script snippet that creates a backup of a directory and logs the result. What will be printed to the console when the script runs successfully?
Bash Scripting
backup_dir="/home/user/documents" backup_dest="/home/user/backup" mkdir -p "$backup_dest" tar -czf "$backup_dest/documents_backup.tar.gz" "$backup_dir" && echo "Backup successful" || echo "Backup failed"
Attempts:
2 left
💡 Hint
The tar command creates a compressed archive. If it succeeds, the echo after && runs.
✗ Incorrect
The script creates the backup directory if it doesn't exist, then runs tar to compress the source directory. If tar succeeds, it prints 'Backup successful'.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this backup script
Which option shows the correct way to write this line to check if the backup directory exists and create it if not?
Bash Scripting
[ ! -d "$backup_dest" ] mkdir -p "$backup_dest"
Attempts:
2 left
💡 Hint
Remember to use 'then' and end the if statement with 'fi'.
✗ Incorrect
Option A correctly uses the if statement syntax with 'then' and ends with 'fi'. Option A misses 'then' and is missing a semicolon or line break. Option A misses semicolons. Option A is invalid syntax.
🔧 Debug
advanced2:00remaining
Why does this backup script fail to create the backup file?
This script is intended to create a compressed backup of /var/log but fails silently without creating the backup file. What is the cause?
Bash Scripting
backup_dir="/var/log" backup_dest="/tmp/backup" mkdir -p "$backup_dest" tar -czf "$backup_dest/var_log_backup.tar.gz" "$backup_dir" > /dev/null 2>&1 if [ -f "$backup_dest/var_log_backup.tar.gz" ]; then echo "Backup created"; else echo "Backup missing"; fi
Attempts:
2 left
💡 Hint
Check permissions for reading system log files.
✗ Incorrect
The /var/log directory usually requires root permissions to read all files. Without sudo, tar cannot read some files, resulting in an empty or no archive. The script suppresses errors, so it fails silently.
🚀 Application
advanced2:00remaining
Which script snippet correctly deletes backups older than 7 days?
You want to automate deleting backup files older than 7 days in /home/user/backup. Which snippet will do this safely?
Attempts:
2 left
💡 Hint
Use find with -mtime and -exec to remove files older than a certain number of days.
✗ Incorrect
Option B uses find to locate files with .tar.gz extension older than 7 days and deletes them safely. Option B is invalid syntax. Option B deletes all files and directories older than 7 days, which may be unsafe. Option B uses a non-existent rm option.
🧠 Conceptual
expert2:00remaining
What is the main benefit of using rsync over tar for backups in scripts?
When automating backups, why might you choose rsync instead of tar?
Attempts:
2 left
💡 Hint
Think about incremental backups and copying only differences.
✗ Incorrect
rsync copies only changed or new files, making backups faster and saving space. tar creates full archives every time. rsync does not compress or encrypt by default.