I have about 40 Raspberry Pi SD-Card backups, dating back several years, with different projects, some of which I barely remember. As they are clogging up my harddrive (400+ GB), I would like to reduce them to a minimum.
The files were mostly created with Win32 Disk Imager, a few maybe with dd.
I would prefer no to write them back to SD card, boot them and check what is on them.
My idea was to mount them in Ubuntu, and retrieve the most common files and directories.
I am mostly interested in:
- the home directory (/home/pi , /home/*)
- including the bash history (~/.bash_history)
I wrote this untested workflow, but I am not experienced with fdisk, grep and bash variables:
#!/bin/bash
for filename in /RPi_images/*.img; do
# creating a filedir for the backed up data
mkdir /RPi_data/$filename
# retrieving boot start off the second partition
bootstrt = $(fdisk -l $filename 2>&1 | grep -o 'img2\s*[0-9]*' | awk '{print $2}')
# multiplying boot start with sector size
# assuming every image has sectors of 512 bytes
offst = $bootstrt * 512
# mount the partition
sudo mount -v -o offset=$offst -t ext4 $filename ~/rpi_mnt
# copy all files from home dir to back up folder
cp -a ~/rpi_mnt/home/. /RPi_data/$filename/home
done
Output of fdisk:
Disk /RPi_images/150101_project1.img: 7.4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xbbda3dc5
Device Boot Start End Sectors Size Id Type
/RPi_images/150101_project1.img1 8192 93236 85045 41.5M c W95 FAT32 (LBA)
/RPi_images/150101_project1.img2 94208 15523839 15429632 7.4G 83 Linux
- How do I manage to get the variables
$bootstrt
$offst
correct? - What else would you recommend an average pi user to back up?