Sunday, April 20, 2014

Backup raspberry pi sd card

Raspberry Pi's SD card can easily become corrupted which prevents pi booting. It has happened to me on a power failure. Best way to avoid this is to back it up. Assuming you have an usb drive mounted on /home/pi/mnt/home/ you can create a bzip2 archive of the sd card with :
sudo dd if=/dev/mmcblk0 | bzip2 > /home/pi/mnt/home/sdimage.bz2
This will take a lot of time. It will create a single file with the sd card image. Later, you can restore the image to the SDcard with the following:
sudo bzip2 -dc /home/pi/mnt/home/sdimage.bz2 | dd bs=1M of=/dev/mmcblk0
-d means decompress
-c means output to standard output
Another way to back it up via tar
tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system / 
sudo tar -xvpzf /path/to/backup.tar.gz -C /media/whatever --numeric-owner

No comments:

Post a Comment