3

I am looking for a way to have the Pi create an image of it's SD card and send it off to a networked file share in a repeatable manner, and then resume operations. I imagine that it would need the entire OS in ram during this time, or at have everything mounted in read-only mode, however I am unsure about this - does anyone have ideas or something similar setup?

non-solutions: anything that would require manual intervention, especially physically moving the SD card into something else - this needs to be able to be completely automated.

1

You are correct in that doing a bare metal backup on a running system needs some crafting. I'm thinking of two possible solutions:

  1. Crate a tarbal archive of the filesystem contents and send it away. This isn't exactly a bare metal backup but may be close enough.
  2. Use an OS which runs entirely from RAM. My project Nard SDK does exactly this. After bootup the SD-card is left alone and you can do whatever you want with it.
  • I am already doing the equivalent of #1, but have had issues with the backups not being correct, so I am moving away from that - #2 may work, however I would like a solution that doesn't cripple the Pi 99% of the time and simply toggles between states if possible. – user2813274 Aug 21 '14 at 17:26
  • OK, how about dual booting? The system could reboot into a small RAM-based OS when it's time for backup and then reboot again when the backup has finished, this time into the "ordinary" OS and resume normal operation. – Ronny Nilsson Aug 21 '14 at 18:58
  • That could work, I will need to look into it (and how to control which of the two systems it boots into automatically) – user2813274 Aug 21 '14 at 18:59
  • 1
    One method could be to have two /boot/config.txt and switch between them, but there are a number or other options too. – Ronny Nilsson Aug 21 '14 at 19:03
4

From my linux machine I run

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

and I just make a point of not doing too much with the pi while its running. 192.168.1.38 is the ip of the Pi

  • and to recover to an SD card on the linux machine gunzip -dc /home/user/raspberry_dd_4M.img.gz | dd bs=4M of=/dev/sdc – rob Aug 20 '14 at 15:08
  • Is there any way to be more sure that you "aren't doing too much" while this is running? i.e. suspend all other threads or something? – user2813274 Aug 20 '14 at 15:10
2

You might want to check out the how you create a NOOBS installer, in which you make tarballs from the running operating system:

https://github.com/raspberrypi/noobs

You can then, if you wish, compress those tarballs with xzinto a NOOBS folder structure which can be copied to an SD and either self-install or menu-install if booted from. I have used this process for my own Raspple II distribution of Raspbian if you want to look at that as a template.

The actual commands I use to make the tarballs (modified from the NOOBS docs) is:

mkdir -p /tmp/usbdisk; sudo mount /dev/sda1 /tmp/usbdisk;
sudo rm /tmp/usbdisk/BOOT.TAR &> /dev/null;
pwd="$PWD"; cd /boot; sudo tar -cvpf /tmp/usbdisk/BOOT.TAR .; cd "$pwd";
sudo umount /dev/sda1; rmdir /tmp/usbdisk

mkdir -p /tmp/usbdisk; sudo mount /dev/sda1 /tmp/usbdisk;
sudo rm /tmp/usbdisk/ROOT.TAR &> /dev/null;
sudo tar -cvpf /tmp/usbdisk/ROOT.TAR /* --exclude=proc/* --exclude=sys/* \
--exclude=dev/pts/* --exclude=/tmp/* --exclude=/var/swap --exclude=/boot/*;
sudo umount /dev/sda1; rmdir /tmp/usbdisk

Once you have the tarball, you need to compress it with xz (as explained in the NOOBS link above) if you want to make it usable with NOOBS, which will probably take all day and night on the Pi; if I use max compression (with the -9 -e options), it takes about an hour to compress on my 1.7 GHz mobile i7 with SSD.

Also, if you do want to use the self-install option (silentinstall), the Raspple II build of NOOBS incorporates a bug fix in which, when Ethernet is attached, the progress bar remains visible and the Pi reboots after installation instead of crashing. This bug fix has not made it into a distribution version of NOOBS yet, though it's in the development branch.

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.