How to make a full backup of your Raspberry Pi without turning it off

There could be scenarios where you wish to make a full backup of you raspberry pi.

This backup/image is flashable using Raspberry Pi Imager and you can fully restore the Pi.

There are few ways you could do this backup:

  • By powering off the Pi/taking out the sdcard and using tools like rufus.
  • Using dd command. Advantage of this way is, you dont have to power off the Pi

Here I am going to explain the second method.

Prerequisites:

  • A share accessible from your Raspberry Pi. This can be a NAS/windows computer or any share which is accessible from Pi.
  • Enough storage space to hold the whole SDCARD size. For eg. If the sdcard is 64GB, the final backup image size would be 64GB.
  • SSH access enabled on Raspberry Pi.

Steps:

  • SSH to the Raspberry Pi.
  • Mount the share on Raspberry Pi using mount command.
sudo mkdir -p /mnt/share
sudo mount -t cifs -o username=USERNAME //IPADDRESS/share /mnt/share
  • Start the backup using dd command.
sudo dd if=/dev/mmcblk0 of=/mnt/share/backup_image.img bs=4M status=progress

Shrunk the img file by removing free size from img file.

wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
chmod +x pishrink.sh
sudo ./pishrink.sh /mnt/share/backup_image.img
  • Un mount the share and release the buffer/cache memory
sudo umount /mnt/share
sudo su -
sync; echo 3 > /proc/sys/vm/drop_caches
exit

Leave a Reply

Your email address will not be published. Required fields are marked *