Raspberry Pi – Backup

Currently, you can read a lot about Raspberry Pi in blogs and forums. There are a lot of topics about ideas and projects but I often miss one very important topic: backup strategies! However which operating system you have Linux, Mac or Windows, you have to make regularly backups otherwise you have to risk to loose data. On your Raspberry Pi you may not have such sensible data like family fotos or business data that are really important for you, but what if you use your Raspberry Pi with a database where you store sensible data from measurements?


If you do not have sensible data you may only need to reinstall your operating system…but if so, you also have an effort to setup and configure. So if you make a regularly backup, a reset is done within some minutes. You can distinguish between two backup strategies:

  • manual backup of your SD card as image
  • automatic backup, while your Raspberry Pi is running

manual backup

The simplest backup you can think of is to make a copy of your SD card. For this you have to stop your Raspberry Pi and put the SD card into another computer. There you can copy the whole contents of your SD card as image onto your laptop or computer. This is slightly different if you have another operating system.

Linux / Mac OSX

if you have an Unix like operating system, it is very simple. You only have to do the following commands in your console/terminal:

Here you should find the path to your SD card (normally it is mounted like /dev/disk1s1).

Now you have to unmount your SD card. The command above is from MacOSX, on linux you only need the unmount command.

With the command dd you can copy the whole contents of your SD card to an image file. Here you should use the correct mount directory from your SD card and then you need to set a directory and filename where the image has to be created. Attention: the image can get big! You can restore your backup (if your SD card has a failure) with the same command! You only have to change if and of. For this it is a good idea to use a formatted SD card with same size.


on Windows you can use the tool¬†win32Diskimager.exe to store data to SD card and to backup data from SD card. For a backup you only need to put a path and filename into ‘Image File’ and then click ‘Read’.

win32diskimager Screenshot

automatic backup

You can also do an automatic backup directly from your Raspberry Pi with a script. For this you need a place where you can store your backup. So you need to connect a USB stick or an external hard disk with appropriate size. Another possibility is to use a network share or a FTP server.


First: you should find out how your SD card is mounted from our Raspberry Pi. You can do this with this commend:

Normally this should be /dev/mmcblk0p2. You can run a backup during runtime with this command:

For the output path ‘of’ you have to set the path to your USB stick, external hard disk or network share. For your daily backup, you can call this command every day with cron.

I found a very useful script which can be used without changes:

I hope you are now backuping your data regularly!

(Visited 2,410 times, 1 visits today)

5 Responses

  1. Dave says:

    Thanks for this great summary!
    There is small typo in the Linux section:
    dd if=/dev/disk1s1 of=/home/backup/backup.img bs=1m
    must be
    dd if=/dev/disk1s1 of=/home/backup/backup.img bs=1M

  2. Thanks! I changed this typo!

  3. Victor says:

    Thanks for this great ideas. tried and works fine.

    Seems than the data in the original SD card (size 16 Gb) is about 3 or 4 Gb. How can i backup to an 8 Gb SD card.

    • Hi, if the data is not bigger than the SD card (here 8 GB), then you can use for example the linux dd command to copy all data to another card. I have not tried it yet, maybe there will be an error in partition size of the new SD card, but I’m sure there is also a possibility on linux to change partition size without destroying data on this partition.

  4. Victor says:

    How can i restore an backup.img


Leave a Reply

Your email address will not be published. Required fields are marked *