this post was submitted on 28 Nov 2024
5 points (85.7% liked)

raspberrypi

3349 readers
2 users here now

Community about the single-board computers, micro-controllers and related projects.

https://www.raspberrypi.com/

Other RaspberryPi communities on Lemmy

founded 4 years ago
MODERATORS
 

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.

with dd

$ fdisk -l
Disk /dev/sda: 29.72 GiB .....
....
Device
/dev/sda1 ...
/dev/sda1 ...

So I first tried:

$ dd bs=4M if=/dev/sda conv=fsync status=progress | gzip > /path/path/foobar.gz

But this create a huge .gz file ! because it backup the unused space too :'(

If you know a ~simple command to just backup the used space I'm all ears.

with rpi-clone

I've discovered rpi-clone

Seem really great, too bad the github tab discussion has been not activated :/ and If the documentation is not clear enough, no way to ask the community.

EDIT: Actually it seem that it clone a SD to a full dest drive ! so not as destination file correct ??

in the README you can read:

rpi-clone-setup is for setting the hostname in /etc/hostname and /etc/hosts files.

It is run automatically by rpi-clone if -s args are given, but before your first clone using a -s option, test run rpi-clone-setup with:

rpi-clone-setup -t testhostname

So what is the purpose of the -s argument ? If you want to set another hostname into the destination backup ? why can we set fews ? Can we have few hostname for a same machine ???

and the -t argument is not even documented (if I'm not mistaken ..)

  • Did you ever tried rpi-clone ?
  • what's your 2cent about it ?
  • does rpi-clone sda promt you to confirm the destination ?
  • do know some thing else ?
  • is it possible to output the backup as a file ?


Thanks.

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

all 5 comments
sorted by: hot top controversial new old
[–] czardestructo 2 points 2 weeks ago

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

[–] bushvin 1 points 2 weeks ago

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.

[–] [email protected] 1 points 2 weeks ago

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.

[–] [email protected] 1 points 1 week ago

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.