Sdcard backup (lesson)

From regional-training

developer

develop configuration management techniques by backup storage images

qualifying statement

Learners will use commands to explore and then [[[backup]] block storage devices. The images may be compressed and used to restore a storage device or partition thereof. There are also means to loop mount the partitions for inspection.

outcomes

backup sdcard

It is very easy to backup your sdcard with Linux:

  • insert the sdcard and carrier into the laptop

If the carrier is a USB carrier then you can observe which disk it shows up with

lsblk

And/or with fdisk

fdisk -l

Once you find the disk carefully use dd.

🚩 Warning: dd is a very dangerous low-level command and can overwrite disk partitions if you get the parameters wrong. How to:

  • save via dd
dd if=/dev/<device-name> bs=10M status=progress of=target-file.img 
  • You may also compress the image on the fly if you want to take up less disk space
dd if=/dev/<device-name> bs=10M status=progress | lz4 > target-file.img.lz4

This is to be copied to the backups on the arising-nas://backups/pi/noobs.img.lz4 for safe keeping.

restore card

Once you have a .img or .img.lz4 compressed image it is an easy matter to restore it to another card, provided the card is large enough. There are, of course, otherways that the partitions can be expanded or shrunk using gparted see

  • look at your computer's current drive layout with
lsblk
  • insert the sdcar and carrier into the computer and inspect again
lsblk

The new drive device, and potentially partitions will be the new sdcard. This is the partition you want to overwrite with your backup image.

🚩 WARNING: the dd command is dangerous, if you select the wrong of= target device you could overwrite your computer. Follow the steps below to restore and image to the card.

  • enter as root
sudo su -
  • if it was a .lz4 compressed image do
lz4 -d <backup.img.lz4> | dd of=/dev/<dev> bs=10M status=progress
  • if the backup was a plain .img do
 dd if=<backup.img> of=/dev/<dev> bs=10M status=progress

Where <dev> is the device indicated via lsblk, and <back.img> is the location of the backup image, <backup.img.lz> the location of the compressed backup image respectively.

categories