2

There's lots of tutorials about using win32diskimager. But a lot of times, the image you make from a 16GB microSD card is too big to restore even on the same 16GB microSD card. It might work, but it might not.

I wish raspi-config's file expansion feature doesn't expand all the way. Is there a more intelligent way making an easy to restore backup?

user1251007
  • 161
  • 11
user851
  • 21
  • 3

6 Answers6

2

I'm not sure on an intelligent way (by that I'm assuming you mean you'd want an automatic solution), but you can manually used gparted (which has a GUI interface) to reduce the size of your main ext4 partition. This would allow you to write it to other cards that are slightly smaller, or depending on how much you shrink your partition, to cards that are much smaller.

npp1993
  • 193
  • 1
  • 9
  • 1
    I shrink my partitions right after initial setup. I have several cards labeled 8 GB that vary slightly. Resizing slightly smaller avoids having to do it with a loaded system later. – bobstro Aug 19 '15 at 04:30
  • Unfortunately shrinking partitions may not work. Unlike HDD, SD cards do not store data sequentially, and due to wear levelling data can be located on any part of the physical SD card. – Milliways Aug 20 '15 at 00:10
2

Once you've expanded your SD card it is difficult to reclaim that space.

The easiest way to back up (albeit not particularly fast due to the SD card size) is to use the dd command such as:

sudo dd bs=1m if=/dev/disk# of=/path/to/backup.img

where bs is the block size (in this case, set to 1 MB), if is the input file (i.e. the disk you are backing up) and of is the output file (i.e. the path and name of your backup).

This is just the reverse of writing an image to a disk.

You could, of course, just write that specific partition such as: dev/disk#s1, etc

You can then save disk space by compressing your backups with

tar zxvf name-of-backup.img </optional/output/path>

AKW
  • 299
  • 1
  • 4
  • 8
2

On the Raspberry Pi desktop (launched by using startx in hard terminal) you can click the menu button (commonly on top left), click accessories, and then SD Card copier. From there you can copy your ENTIRE SD CARD to a flash drive, hard drive, or another SD card if you have an adapter. I use this to backup both partitions of my SD card.

Dallin Wright
  • 81
  • 1
  • 1
  • 9
1

There are 2 common approaches to backing up the Pi.

The most common uses dd or a program e.g win32diskimager to make an exact copy of the SD card. These copy the MBR (which is not used by the pi for booting) plus all partitions, including any unused space.

This produces large images (which can be compressed) and has the risk of being too large to restore, although this is not common. I use this approach and have had no problems restoring to different SD cards. There are ways of working around this, but this is complicated, and requires an understanding of Linux and disk structure.

NOTE the size of the image is unaffected by raspi-config's file expansion feature.

The other common approach is to copy files to another device. My implementation of this is described in https://raspberrypi.stackexchange.com/a/28087/8697

There is a third approach, which is to make copies of individual partitions, then restoring these. This is complex, not least because the way partitions are allocated on the Pi differs from the normal default used by most partitioning software (this is done for efficient utilisation of the blocks on the SD card, so partitions are contained within a number of blocks with no overlap).

You will find literally hundreds, if not thousands of posts on each of these, unfortunately not all are technically correct.

Milliways
  • 54,718
  • 26
  • 92
  • 182
1

My Raspis create a backup every week on my NAS space with raspiBackup. Use dd if you need to restore it from Windows or use tar or rsync otherwise. rsync uses hardlinks and the backup time and -space required is quite small. Give it a try.

framp
  • 872
  • 7
  • 15
0

For a more user-friendly and flexible backup option, you may wish to consider installing deja-dup

This can be easily installed via the Synaptic Package Manager if you have it, or via command line

deja-dup will allow you to selectively back up folders and files at scheduled times to a connected drive