Skip Navigation

Backup boot SD card ( without unused space )

Hi,

I would like to backup the booted SDcard of my Raspberry pi.

I don't necessary need to backup as a hot backup[^1] So I can remove the SDcard and make the backup on another machine.


\ Thanks.

[^1]:Backup that can be taken while the system is running.

4 comments
  • Put the sdcard in a Linux box with a GUI

    Step one: shrink the image size use gparted, re-size the main partition to as small as possible

    Step two: run fdisk to find out the last used sector. Command: sudo fdisk -l /dev/mmcblk0

    Step three: get the 'end' sector from the last partition and enter it into the dd command below as 'count'. Run the dd command with a stop at the last used sector and correct bytes per sector set: sudo dd bs=512 count=12281855 if=/dev/mmcblk0 of=/home/pi/Azle.iso status=progress

  • Thanks all for your input,

    I've found what works very well fsarchiver ! that can make live (or not) system backup awesome piece of software.

  • What kind of backup do you want to take? A config backup or a live system backup?

    Live system backups are difficult, as you typically have locked files and files being written to. You would need agents which allow your apps to be suspended is a consistent state. Besides that you have mounted pseudo file systems which you don’t need to backup like /tmp, /sys, /proc. You could use file system snapshots, but not all fs support this. And knowing the default fs used on rpi, you’re out of luck.

    Config backup on the other hand can be done rather easily. You list the dirs and files and you’re off. I use restic, which is a very flexible backup tool leveraging compression, snapshots and encryption. It even allows you to use cloud storage natively to store your backups.

  • I just recently switched over to rpi-clone after doing backups of the booted SD with SD Card Copier, the GUI app on Raspberry OS.

    The original version from billw2 didn't work with modern OS versions. After doing some lookups in the issues and online, the users pointed to geerlingguy's version, which seems to be maintained.

    I'm not using rpi-clone-setup but rpi-clone sdX and after trying it for the first time, it worked. I swapped out the SD with the copy and the raspberry booted (it didn't boot with billw2's version).

    Next step is to create a script for regular backups.

    To your questions:

    • Tried it, it works for my use-case
    • rpi-clone asks for confirmation, which I need to address when trying to do backups automatically
    • Have tried others but needed a working copy on a new SD card, so this is the solution I'm going with
    • If you want a file you probably want to use dd. I'm aware of the space issue. I quickly looked up other tools: partclone and fsarchiver seem to address the free space issue, but I never tried them so I cannot speak to that.