0

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.

UNKNOWN
  • 79
  • 3
  • 18
  • 1
    I could use a little more clarification for these answers. – UNKNOWN Jun 18 '20 at 20:28
  • I agree on the "more clarification needed" point. I don't know what "retro pi" is (another clever marketing gimmick from the House of Pi?), BUT you might consider `image-utils` as a potential solution. I've posted [several answers](https://raspberrypi.stackexchange.com/search?q=user%3A83790+image-utils) here that proposed `image-utils` as a backup solution - [this one](https://raspberrypi.stackexchange.com/a/109364/83790) in response to a long-standing question that has other solutions you may find useful. – Seamus Jul 06 '21 at 19:42

3 Answers3

4

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
Swedgin
  • 264
  • 1
  • 8
  • As far as I understand the OP like to backup the running system itself. This isn't possible with `dd`. – Ingo Jun 18 '20 at 08:27
  • @Ingo It's an SD card he wants to back up. Put it into a card reader, et viola – Swedgin Jun 18 '20 at 08:33
  • @Swedgin Have you tested this? – UNKNOWN Jun 18 '20 at 12:01
  • @UNKNOWN yes, this is a known command in linux (https://man7.org/linux/man-pages/man1/dd.1.html). – Swedgin Jun 19 '20 at 07:32
  • @Swedgin Is "/dev/sda" The location of my raspberry pi's SD card? – UNKNOWN Jun 19 '20 at 17:38
  • @UNKNOWN I've updated my post with more information. Let me know if it's clear – Swedgin Jun 19 '20 at 17:49
  • @Swedgin I want to know if this simply will take the information off the pi, and copy it to an SD card that I can swap with the one in the pi. – UNKNOWN Jun 19 '20 at 18:01
  • @MichaelHarvey Can I flash that image with Etcher? – UNKNOWN Jun 19 '20 at 19:09
  • @UNKNOWN, yes, this will basically copy the whole SD-card to an image the same size, including partition table. So restoring this to an SD-card the same size or bigger will get you the exact same system you've backup'd. I use the same method for my SDD on my laptop. – Swedgin Jun 19 '20 at 20:00
  • @MichaelHarvey Yes, you can do a `dd` of the running system itself but you do not get a consistent image because of dynamically changed files during backup which may break the restored image. – Ingo Jun 19 '20 at 21:09
3

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...

1

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

Etescartz
  • 11
  • 1