3

I have a large SD card ~60G. I expanded Rasbian to the entire disk but now I want to make backups. Preferable backups that aren't 60G. How do those with large SD cards go about this?

Granted I'm only using a small fraction of the entire card.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           59G  850M   56G   2% /
/dev/root        59G  850M   56G   2% /
devtmpfs        215M     0  215M   0% /dev
tmpfs            44M  248K   44M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            88M     0   88M   0% /run/shm
/dev/mmcblk0p1   56M  9.7M   47M  18% /boot
5

You can pipe dd backups into gzip, as the blocks are 0 when unused they are highly compressible.

ssh pi@192.168.1.38 sudo dd bs=4M if=/dev/mmcblk0 | gzip -c > raspberry_dd_4M.img.gz

or from a linux card reader

dd if=/dev/sdc bs=4M | gzip > rasppi_4M.img.gz

and the obligatory recovery command

gunzip -dc /home/user/raspberry_dd_4M.img.gz | dd bs=4M of=/dev/sdc

I took the above from a blog post I wrote in June 2013

3

You also can use tar to backup your root and boot partition. tar will backup only used space.

To backup the root partition you can use following command:

tar -cvpzf /root.tar.gz --exclude=/root.tar.gz --one-file-system / 

To backup the boot partition you can use following command:

tar -cvpzf /boot.tar.gz --exclude=/boot.tar.gz --one-file-system /boot
  • This answer is pretty short, and is really more of a comment. I am voting against deletion, but please expand your answer to include how such a thing would be done. – Jacobm001 May 29 '15 at 21:12
  • Well, I assumed everybody knows tar - but you are right - I cannot assume this all the time. I updated the answer and included sample tar commands to use to backup the partitions – framp May 30 '15 at 10:14
1

While not exactly answering your question it still might help. There are tools available - such as partimage - making compressed images of partitions. So no matter how large a partition is, the image size will be mainly influenced by the disk usage.

On a side not however: partimage is not working on ext4 or btrfs filesystems; is doing no defragmentation before saving an image; and needs the filesystem to be unmounted prior to saving.

1

Another alternative is to use pishrink

PiShrink is a bash script that automatically shrinks a pi image that will then resize to the max size of the SD card on boot. This will make putting the image back onto the SD card faster and the shrunk images will compress better.

The algorithm mounts the image on a loop device, executes e2fsck, calculates the minimum space required by the second partition, adds some spare space and finally executes resize2fs to shrink the second partition to the calculated minimum size.

0

There's a ready made solution to this question: the script only backs up used space and can be done whilst running on the Pi you want to back up!

https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi/make-a-backup-image

  • Could you also explain why this solves the problem? – RalfFriedl Apr 21 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.