Skip to content

Instantly share code, notes, and snippets.

@kiraitachi
Forked from eliroca/backup_raspberrypi.md
Created January 8, 2024 10:08
Show Gist options
  • Save kiraitachi/9bcfec9931a684957ae828b785b98c21 to your computer and use it in GitHub Desktop.
Save kiraitachi/9bcfec9931a684957ae828b785b98c21 to your computer and use it in GitHub Desktop.
Use ssh and dd to Remotely Backup a Raspberry Pi

You can make a backup of your pi and have the backup written to your regular PC all from the command line.

From your local machine, run the remote backup command:

ssh pi@xx.x.x.xx "sudo dd if=/dev/mmcblk0 bs=1M | gzip -" | dd of=/path/to/pibackup.gz

After 47min 21sec, in my case, got this as output:

30436+1 records in
30436+1 records out
31914983424 bytes (32 GB, 30 GiB) copied, 2830.89 s, 11.3 MB/s
4637363+1 records in
4637363+1 records out
2374329939 bytes (2,4 GB, 2,2 GiB) copied, 2841,61 s, 836 kB/s

If you ever need to use your back up you cannot do it remotely (at least that I know of).
You will need to insert the SD card into your local machine and run the following commands:

diskutil unmountDisk /dev/disk#

gzip -dc /path/to/pibackup.gz | sudo dd of=/dev/rdisk# bs=1m conv=noerror,sync

Source link here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment