0
0
Raspberry Piprogramming~10 mins

Backup and recovery strategies in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a backup of the Raspberry Pi SD card using the dd command.

Raspberry Pi
sudo dd if=/dev/mmcblk0 of=[1] bs=4M status=progress
Drag options to blanks, or click blank then click option'
A/backup/pi_backup.img
B/home/pi/backup.img
C/dev/sda1
D/tmp/backup.img
Attempts:
3 left
💡 Hint
Common Mistakes
Using a device path instead of a file path for the output.
Not specifying the output file path.
2fill in blank
medium

Complete the command to restore the Raspberry Pi SD card from a backup image.

Raspberry Pi
sudo dd if=[1] of=/dev/mmcblk0 bs=4M status=progress
Drag options to blanks, or click blank then click option'
A/tmp/restore.img
B/dev/mmcblk0
C/home/pi/backup.img
D/backup/pi_backup.img
Attempts:
3 left
💡 Hint
Common Mistakes
Using the device path as input file instead of the backup image.
Mixing up input and output file paths.
3fill in blank
hard

Fix the error in the command to compress the backup image using gzip.

Raspberry Pi
gzip [1]
Drag options to blanks, or click blank then click option'
A/backup/pi_backup.img
B/home/pi
C/tmp
D/dev/mmcblk0
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to gzip a device path or directory.
Not specifying the file to compress.
4fill in blank
hard

Fill both blanks to create a script that checks if the backup file exists and then copies it to a USB drive.

Raspberry Pi
if [ -[1] /backup/pi_backup.img ]; then
  cp /backup/pi_backup.img [2]/pi_backup.img
fi
Drag options to blanks, or click blank then click option'
Ae
B/media/usb
Cf
D/mnt/usb
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong test flag like -f which checks if it is a regular file but might fail if symbolic links exist.
Using incorrect USB mount path.
5fill in blank
hard

Fill all three blanks to create a Python dictionary comprehension that maps filenames to their sizes only if size is greater than 1000 bytes.

Raspberry Pi
sizes = { [1]: [2] for [3] in files if os.path.getsize([3]) > 1000 }
Drag options to blanks, or click blank then click option'
Afilename
Bos.path.getsize(filename)
Dfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in key, value, and loop variable.
Not calling os.path.getsize correctly.