I'm trying to back up my retro pie SD card in case of corruption, but Retro pie does not have a desktop environment, so can't use the sd card copier tool. Is there some terminal command to do this? I'm using a raspberry pi4 and the official retro pie image.
3 Answers
You can use dd, this applies also for creating an image of an SDD, USB, ... and restoring it
It's best to unmount the drive you're going to copy. In case of the SD-card, remove the SD-card from the RPi and put it into a card reader. Don't mount.
The basic command is this:
dd if=input_file of=output_file status=progress
Use lsblk to determine the name of the drive, eg. /dev/sdb
So if your SD-card/USB/SDD is on /dev/sdb:
sudo dd if=/dev/sdb of=/path/to/folder/backup.img status=progress
to restore
sudo dd if=/path/to/folder/backup.img of=/dev/sdb status=progress
Don't output the file onto the same SD card. Use another drive. You can use the block size BS to use bigger blocks. Eg. BS=4M
If you want, you can pipe the image directly into a compressed file.
Eg. using gzip
sudo dd if=/dev/sdb | gzip > /path/to/folder/backup.img.gz
To restore:
gunzip -c /path/to/folder/backup.img.gz | sudo dd of=/dev/sdb status=progress
Taken from the question over at unix.stackexchange. To backup from your computer over ssh without removing the SD-card
ssh user@remote "dd if=/dev/sda | gzip -1 -" | dd of=image.gz
- 264
- 1
- 8
Have a look through Using rsync to backup Pi
You need to set the exclusions to include where the roms are stored.
I would question why not backup the rom files though? Restoring the machine WHEN (not if) the SD card fails will take significantly longer if you have to download / find all the rom files again...
I don't think there is on command in either Linux or the RetroPi setup to achieve this but you can use either :
https://github.com/crcerror/RetroPie-Simple-Backup-Script
OR
https://github.com/kallsbo/BASH-RaspberryPI-System-Backup
There may be other scripts or options available if you do a web search. In Linux at least Bash scripts are your friends :D
- 11
- 1