1

I have 4 Pis. On each Pi I have mounted my Airport Extreme (Apple router that has built in storage) to /home/pi/Airport. I would like to automatically backup each Pi on a set interval. Would doing something like dd if=/dev/root of=/home/pi/Airport/image.gz be dangerous with the network storage mounted? What would be the proper way to clone the Pi from itself and copy that image to the Airport Extreme?

K. Shores
  • 113
  • 1
  • 5

2 Answers2

3

You can use dd on a Linux machine to write to any mounted storage. This writes raw blocks, so should work.

Restoring the image files is another problem.

NOTE There is no such thing as /dev/root. On the Pi the SD Cards is at /dev/mmcblk0

You probably need sudo to grant dd the necessary permission to access the devices.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • I wasn’t sure if dd would try to traverse network connected storage or not, thanks. If I had to restore, I would use my computer to copy from the network drive to another sd card – K. Shores May 23 '19 at 00:37
  • Also the output of df lists /dev/root as the mounting point for / for me, so that’s what I thought I should use – K. Shores May 23 '19 at 00:38
3

It is not a good idea to take an image from a running system. During backup the system will dynamically change important system files and caching so you do not get a consistent backup. It is not guaranteed to restore a running system because system files may not match.

This is a well known problem and you have to take some effort to avoid this. The easiest way is to boot into read only mounted file systems but mostly not practicable.

You can look at Can a Raspberry Pi be used to create a backup of itself? how to use rsync to update a running system.

If you like to take one time some effort then you can do very simple backups like you intend to do. You can use logical volumes, just make a snapshot and backup the snapshot. How to do it you can look at Easy backups and snapshots of a running system with LVM.

Ingo
  • 40,606
  • 15
  • 76
  • 189
  • Oh, thank you for this. I know how to use rsync but I was interested in being able to copy from the network card to the SD card with DD. I also want all of my configuration files and installed packages to be included. I guess I can use rsync for this instead. – K. Shores May 24 '19 at 00:48
  • @K.Shores I'm not sure if I understand. You have a RasPi running. On this running RasPi you have mounted a remote storage. Now you want to backup the boot and root file system of itself (the running RasPi) to the remote storage. Isn't it? If so it doesn't make a difference if you do a `dd` or use `rsync` without additional excludes. – Ingo May 24 '19 at 00:59
  • To be honest, I had not considered the in memory files. I assumed that since dd copies blocks of memory, that the in memory files would somehow be excluded. Clearly I am wrong. – K. Shores May 24 '19 at 01:02
  • @Ingo, I agree with your reservations. HOWEVER `rsync` is NOT a viable solution (unless to a HD attached to the Pi or a Linux filesystem), and CERTAINLY won't work on an Apple OS, which has a different user structure, and blocks paths Apple deems unsuitable. The suggested procedure is viable for saving copies of files - but I wouldn't use it to restore an OS. – Milliways May 24 '19 at 03:54
  • @K.Shores actual in-memory files will NOT be copied, as dd is doing a copy of blocks on the SD Card. It, of cause, risks losing uncommitted files, because dd has NO KNOWLEGE of the filesystem. – Milliways May 24 '19 at 04:01
  • @Milliways OK, I don't have any experience with an Apple OS. But with **lvm** you should be able to make a consistent backup from a snapshot and store it on a remote share as long as you can write any file to it. – Ingo May 24 '19 at 07:54