Challenge - 5 Problems
Raspberry Pi Backup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Raspberry Pi backup script snippet?
Consider this Python script running on a Raspberry Pi to create a backup of a directory. What will be printed after execution?
Raspberry Pi
import os backup_dir = '/home/pi/backup' source_dir = '/home/pi/data' os.system(f'mkdir -p {backup_dir}') os.system(f'cp -r {source_dir}/* {backup_dir}/') print('Backup completed')
Attempts:
2 left
💡 Hint
The script creates the backup directory if it doesn't exist and copies files.
✗ Incorrect
The script uses os.system to create the backup directory and copy files. If the directories exist and permissions are correct, it prints 'Backup completed'.
❓ Predict Output
intermediate2:00remaining
What error does this recovery script raise?
This Python snippet attempts to restore files from a backup folder on a Raspberry Pi. What error will it raise if the backup folder does not exist?
Raspberry Pi
import shutil backup_dir = '/home/pi/backup' restore_dir = '/home/pi/data' shutil.copytree(backup_dir, restore_dir)
Attempts:
2 left
💡 Hint
copytree requires the source directory to exist.
✗ Incorrect
If the source directory does not exist, shutil.copytree raises FileNotFoundError.
🧠 Conceptual
advanced2:00remaining
Which backup strategy minimizes data loss on a Raspberry Pi?
You want to back up your Raspberry Pi data regularly. Which strategy best minimizes data loss if the Pi crashes unexpectedly?
Attempts:
2 left
💡 Hint
Think about how often data changes and how quickly you want to recover.
✗ Incorrect
Incremental backups every hour save only changes since the last backup, minimizing data loss and storage use.
❓ Predict Output
advanced2:00remaining
What is the output of this Raspberry Pi backup verification script?
This Python script checks if the backup directory contains the expected number of files. What will it print if the backup has exactly 5 files?
Raspberry Pi
import os backup_dir = '/home/pi/backup' files = os.listdir(backup_dir) if len(files) == 5: print('Backup verified') else: print('Backup incomplete')
Attempts:
2 left
💡 Hint
The script counts files and compares to 5.
✗ Incorrect
If the backup directory has exactly 5 files, the script prints 'Backup verified'.
❓ Predict Output
expert2:00remaining
What is the value of variable 'status' after running this Raspberry Pi backup script?
This Python script attempts to back up a directory and sets 'status' based on success. What is the value of 'status' after running?
Raspberry Pi
import subprocess backup_dir = '/home/pi/backup' source_dir = '/home/pi/data' try: subprocess.run(['cp', '-r', source_dir + '/*', backup_dir], check=True) status = 'Success' except subprocess.CalledProcessError: status = 'Failed'
Attempts:
2 left
💡 Hint
Check how subprocess.run handles shell wildcards without shell=True.
✗ Incorrect
The wildcard '*' is not expanded without shell=True, so the command fails and status is set to 'Failed'.