Bird
Raised Fist0
Raspberry Piprogramming~10 mins

Backup and recovery strategies in Raspberry Pi - Interactive Code Practice

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of creating backups on a Raspberry Pi?
easy
A. To install new software automatically
B. To speed up the Raspberry Pi's processing power
C. To save copies of important files in case of data loss
D. To increase the screen resolution

Solution

  1. Step 1: Understand the concept of backup

    Backups are copies of important data saved separately to prevent loss.
  2. Step 2: Identify the main purpose on Raspberry Pi

    On Raspberry Pi, backups protect files from accidental deletion or corruption.
  3. Final Answer:

    To save copies of important files in case of data loss -> Option C
  4. Quick Check:

    Backup = Save copies [OK]
Hint: Backups protect data by saving copies elsewhere [OK]
Common Mistakes:
  • Confusing backup with speeding up the device
  • Thinking backup installs software
  • Assuming backup changes display settings
2. Which command is commonly used on Raspberry Pi to create a full image backup of the SD card?
easy
A. rsync
B. dd
C. cp
D. mv

Solution

  1. Step 1: Identify commands for backup

    rsync copies files, dd creates exact disk images, cp copies files, mv moves files.
  2. Step 2: Choose command for full SD card image

    dd is used to create a full image backup of the SD card on Raspberry Pi.
  3. Final Answer:

    dd -> Option B
  4. Quick Check:

    Full image backup = dd [OK]
Hint: Use dd for full SD card image backups [OK]
Common Mistakes:
  • Using rsync for full disk image instead of file sync
  • Confusing cp or mv with disk imaging
  • Not knowing dd creates exact disk copies
3. What will be the output of this command on Raspberry Pi?
rsync -av --delete /home/pi/data/ /backup/data/
medium
A. Copies files from /home/pi/data/ to /backup/data/ and deletes files not in source
B. Copies files from /backup/data/ to /home/pi/data/ without deleting
C. Deletes all files in /home/pi/data/ without copying
D. Moves files from /home/pi/data/ to /backup/data/ without copying

Solution

  1. Step 1: Understand rsync options

    -a means archive (copy recursively with attributes), -v means verbose, --delete removes files in destination not in source.
  2. Step 2: Analyze source and destination paths

    Files are copied from /home/pi/data/ to /backup/data/ with deletion of extra files in destination.
  3. Final Answer:

    Copies files from /home/pi/data/ to /backup/data/ and deletes files not in source -> Option A
  4. Quick Check:

    rsync -av --delete = sync with deletion [OK]
Hint: rsync --delete syncs source to destination exactly [OK]
Common Mistakes:
  • Confusing source and destination order
  • Thinking rsync moves files instead of copying
  • Ignoring --delete option effect
4. You run dd if=/dev/mmcblk0 of=backup.img but get a 'Permission denied' error. What is the likely fix?
medium
A. Run the command with sudo to get admin rights
B. Change the output file name to backup.txt
C. Use rsync instead of dd
D. Restart the Raspberry Pi and try again

Solution

  1. Step 1: Understand permission error cause

    Accessing /dev/mmcblk0 requires admin rights, normal user lacks permission.
  2. Step 2: Fix by running with elevated rights

    Using sudo runs the command as admin, allowing access to device files.
  3. Final Answer:

    Run the command with sudo to get admin rights -> Option A
  4. Quick Check:

    Permission denied = need sudo [OK]
Hint: Use sudo for commands accessing system devices [OK]
Common Mistakes:
  • Changing file extension does not fix permission
  • Switching to rsync won't fix device access
  • Restarting doesn't change permissions
5. You want to automate daily backups of your Raspberry Pi's important files to an external USB drive. Which approach is best?
hard
A. Manually copy files every day using file manager
B. Install a game that backs up files automatically
C. Use dd to create a full SD card image every hour
D. Write a script using rsync and schedule it with cron

Solution

  1. Step 1: Identify automation tools on Raspberry Pi

    rsync efficiently copies files; cron schedules tasks automatically.
  2. Step 2: Choose best method for daily automated backup

    Writing a script with rsync and scheduling with cron automates daily backups reliably.
  3. Final Answer:

    Write a script using rsync and schedule it with cron -> Option D
  4. Quick Check:

    Automate backups = rsync + cron [OK]
Hint: Use cron with rsync for automated backups [OK]
Common Mistakes:
  • Relying on manual copying is not automated
  • Using dd hourly wastes space and time
  • Installing unrelated software won't backup files
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard