It happens to everyone at one point or another—you've put hours into perfecting your Raspbian installation, setting up applications, and hacking away at clever code, when out of nowhere your cat/dog/next-of-kin swoops down on your keyboard and triggers the self-destruct mechanism from the Erasing the Pi should it fall into the wrong hands section in Chapter 5, Taking Your Pi Off-Road.
Not to worry, Agent, backing up an SD card is quite simple as long as you've got the required disk space to store it.
We'll be making a complete mirror image of your SD card. The data will be stored in a single file that will be the same size as that of your SD card. To do this, we'll use the Win32 Disk Imager application we installed earlier on to create our SD card image:
$ sudo shutdown -h now
.img
.
Once your image backup has completed successfully, you can compress it to save quite a bit of disk space. Just right-click on the image file and select Send to, then click on Compressed (zipped) folder.
We'll be making a complete mirror image of your SD card. The data will be stored in a single compressed file, which should result in a smaller size than that of your SD card. The steps to be followed for a data backup are as follows:
$ sudo shutdown -h now
/Applications/Utilities
on the Mac).diskutil
list
to obtain a readout of all connected storage devices.[disk]
with the IDENTIFIER field of your SD card:$ diskutil unmountdisk [disk]
agent_sdcard.img.gz
on your desktop. Type the following command, but replace [disk]
with the IDENTIFIER field of your SD card (note the letter r in front of disk):$ sudo dd if=/dev/r[disk] bs=4m | gzip > ~/Desktop/agent_sdcard.img.gz
sudo
is allowed to start. The backup process doesn't produce much output as it runs, but a status report can be produced by pressing Ctrl + T in the Terminal
window:
To restore your SD card from a backup image, repeat the previous steps, but use this command instead at step 7:
$ gzip -dc ~/Desktop/agent_sdcard.img.gz | sudo dd of=/dev/r[disk] bs=4m
We'll be making a complete mirror image of your SD card. The data will be stored in a single compressed file, which should result in a smaller size than that of your SD card:
$ sudo shutdown -h now
sudo lsblk -f
to obtain a readout of all connected storage devices.vfat
and one ext4
entry under FSTYPE
(there will be two of each type if we installed Raspbian through NOOBS).NAME
(sdb
in the screenshot).NAME
have a MOUNTPOINT
listed, you should unmount it first. Use the following command, but replace [mountpoint]
with the mountpoint of your partition:$ sudo umount [mountpoint]
agent_sdcard.img.gz
in your home
directory. Type the following command, but replace [disk]
with the NAME
of your SD card:$ sudo dd if=/dev/[disk] bs=4M | gzip > ~/agent_sdcard.img.gz
sudo
pkill
-USR1
dd
in another terminal
console:
To restore your SD card from a backup image, repeat the previous steps, but use this command instead at step 7:
$ gzip -dc ~/agent_sdcard.img.gz | sudo dd of=/dev/[disk] bs=4M
3.15.29.119