How to Backup a Raspberry Pi SD Card guide
Learn different ways of how to a backup
your Raspberry Pi SD card to save your files from occasional loss
|Raspberry Pi SD card backup is what you really need if you work on Raspbian. Believe me, you do! If you backup your Raspberry Pi SD card in due course, someday it may save your files and your project. Alike any other hardware, the RPi devices may sometimes simply stop working.It can occur due to a number of reasons: overheating, errors, energy supply issues, cable connection failure… All these problems will make you unplug and plug-in again the device to restart it. And such actions taken repeatedly will certainly lead to spoiling your SD card you are saving your work files to.|
|On the other hand, you can damage or delete your files occasionally with your own hands! There a lot of examples when we do something wrong because of the overall tiredness, inattentiveness or just being in a hurry.Also, another reason to backup Raspberry Pi is the simplicity of starting all of the work over. I mean if you are completely messed up while doing some project on your RPi, it takes very short time to delete everything, reinstall the Raspbian and start from the last successfull point! This is very simple in case you back up the file system properly.Finally, you may want to duplicate what you’ve done. In this case, it is very convenient to clone the Raspbian image (which is also a kind of backup) and reuse it again somewhere else.So, you should do the backup of your Raspberry Pi over the network or literally make your RPi clone to keep your life in harmony!OK, now I hope you understand the importance of backing up your Raspberry Pi SD card. Below we describe 3 ways to do that.|
How to backup a Raspberry Pi SD card
This way fully depends on your particular goals and wishes. By using SD card backup approach you may either copy the entire image of your file system or choose only to copy selected data to your SD card. If you would like to act the simplest way by storing the separate data or files, simply set up WinSCP client on your Windows PC device, connect to Raspberry Pi via SFTP connection and copy the particular files you need directly from RPi.
On the other hand, creating the whole image of Raspbian may be quite reasonable. It implies cloning the whole file system structure. So, you make a clone of SD card, write the copied image to a new SD card then just plug it in a new RPi and you have a full clone of the original device. If you chose to build this way of a backup, everything will depend on the operating system you are going to use: Linux, Mac or Windows.
Backup your Raspberry Pi SD Card using Linux
When you backup the Raspberry Pi SD card you need to use some additional desktop. In case of Linux one, which Raspbian is very close to, you should define the SD card the first step. Here’s how:
1. Open up the terminal and fulfill the command (no SD should be in): df -h. You should see an output like this
2. Now, insert the SD card from your RPi device, you would like to back up and repeat the same command (df -h):
The two extra lines in the bottom that you can see in the picture are your SD card. In this case, it’s called “mmcblk0p1”. It’s important to remove the last “p1” from the title, as this “p1” means the partition of the disk and we need the entire SD to be imaged. So don’t forget to remove this “p1” from what we are going to do further.
Finally, use the standard command to finish the backup:
|dd if=/dev/sdx of=~(path to image)/file.img bs=1M|
Note, that “/dev/sdx” should be your SD card. As the result, the entire SD card will be copied to the directory you have provided. After that, you can do the vice versa. I mean copy the entire image to some another SD card, to fully clone it or just to restore what you have saved.
To do that, you should repeat the first two steps but with a new SD card, you’re going to restore the image to. After that, do the following command to unmount all the existing partitions, based on what kind of output you see for the new SD card (if they have more than one “p”, like “p2”, “p3”, etc. ):
|sudo umount /dev/sdb1sudo umount /dev/sdb2|
After that, you can write the image to the SD:
|sudo dd bs=4M if=~(path to image)/file.img of=/dev/sdb|
Where “bs=4M” means that you reserve the 4Mb of space as a “block size”. In case you receive any warnings or error messages, simply change this value to “1M”
Important NOTE! All the commands are carried out without any notification, so whether you are backing up the image, or restoring it, make sure the process is over before ejecting your card. For that use the command:
Backup your Raspberry Pi SD Card using MAC
Working on Mac, you have to figure out what’s your SD card title in the system as well. So, open up a terminal and input:
You will get the list of your memory card drives and devices connected. Identify your SD card among them through the proper name and/or size. It should anyway look something like “/dev/disk1”.
You can use the same “dd” command here, but have to change your SD card designation:
|dd if=/dev/rdiskx of=~(path to image)/file.dmg bs=1M|
As you’ve already understood, /dev/rdiskx goes for your SD card. And again, the restoration is done with the first identification steps and then unmounting the SD card partitions and writing an image back to an SD:
|diskutil unmountDisk /dev/rdiskxsudo dd if=~(path to image)/file.dmg of=/dev/rdiskx|
That’s it. The only thing is highly recommended is that you properly eject the SD before taking it out of the slot physically:
|sudo diskutil eject /dev/rdiskx|
Backup your Raspberry Pi SD Card using WINDOWS
You’ll need a small additional app here, called Win32DiskImager. This app will help you to create the Raspberry Pi image from files kept on your SD card and store it safely on your PC. To make the Raspbian image follow these steps
- Download Win32DiskImager from the SourceForge
- Safely remove your SD card from the RPi and insert it into your PC slot
- Open Win32 Disk Imager
- Choose the name and location of the backup file and the letter for your SD card and
- Click “Read”
Wait for a little while for the system to create an image of the SD card. Usually, it takes several minutes, depending on the size of the card memory. After that, your Raspbian is fully backed up.
Raspberry Pi Backup with CrashPlan
CrashPlan on Raspberry Pi is what I have already written about. Copying files or full image are a manual kind of work. But you definitely need the automatic backup for your Raspberry Pi. CrashPlan is one of the kind. CrashPlan can back up your files to both cloud and your PC or laptop and even on PC of your friend 🙂 Backup to the cloud is a paid option which includes different pricing plans. Other ones are free. For that, you need a CrashPlan client running on Raspbian.
So, here is where you need ExaGear Desktop. It’ll enable running the x86 CrashPlan app on a Raspberry Pi device. After you get the ExaGear license or at least a demo, follow the instructions below.
As a zero step toy need to download CrashPlan from the official website www.crashplan.com. Note, that you need the Linux version! Then:
1. Unpack ExaGear Desktop archive:
|cd home/pi/Downloadstar -xvzpf exagear-desktop-rpi*.tar.gz|
2. Install ExaGear:
|$ sudo ./install-exagear.sh|
Start guest x86:
3. Enter the guest x86 system using the following command:
|exagearStarting the shell in the guest image /opt/exagear/images/debian-8|
Check if guest x86 system is on:
There should be the return:
4. Update the guest system:
|$ sudo apt-get update|
5. Download libraries necessary for CrashPlan:
|$ sudo apt-get install lxrandr libgtk2.0-0 libXtst6 cpio|
6. Unpack the CrashPlan archive, from the default RPi directory (usually, Downloads folder):
|cd /home/pi/Downloadstar -xvzpf CrashPlan_4.8.2_Linux.tgz|
7. Install CrashPlan on the x86 guest system and from the directory, CrashPlan has been unpacked into:
|cd /home/pi/Downloads/crashplan-install$ sudo ./install.sh|
8. Follow the prompts of the installation manager and then configure an auto start:
|$ sudo service crashplan start 2>/dev/null$ sudo update-rc.d crashplan enable|
9. That’s it! Now, you can run CrashPlan with the following command:
Otherwise, you can run CrashPlan from the Start menu:
You’ll see a browser window with the empty fields. Fill them out and start up your account and start the backing up.
Backup your Raspberry Pi with Dropbox
Using Dropbox for file system backup on Raspberry Pi is a little bit different approach. It also uses a desktop app to set the process. So what’s the deal? And what’s the main difference from free CrashPlan automatic backup we have looked through earlier?
The main magic of Dropbox on Raspberry Pi is in its data recovery and file versions history access. In fact, Dropbox keeps a history of all versions of the files. With Dropbox, you can restore files for the duration of up to 30 days (120 days for extended business version). Moreover, you can get the access to all those versions online, from any device (even mobile) and from any place 24/7.
So, all you need is to set up Dropbox on Raspberry Pi and use it during your work, storing all the files to Dropbox dedicated folder. Dropbox will do the rest. For any occasion, you’ll be able to restore different versions of files, that’s even better than a pure backup. Worth money and efforts, I guess.
Installation Dropbox on Raspberry Pi
The process is very close to what we have done earlier with CrashPlan and you will need ExaGear in this case as well. So, follow these steps:
1. Download and install ExaGear just like in we did it in the previous chapter.
2. Install necessary libraries for Dropbox:
|$ sudo apt-get install wget libxslt-dev libxxf86vm-dev xcb|
3. Download Dropbox 32-bit Debian archive:
4. Unpack and launch the installation:
|$ sudo dpkg -i dropbox_2015.10.28_i386.deb; sudo apt-get install -f|
5. Run Dropbox:
At the first launch, Dropbox runs the installation daemon. Press “ok” and wait until the installation finishes.
5. You can also set up an autostart for Dropbox:
|$ archarmv7$ sudo su$ printf ‘#!/bin/bash\nexec exagear — $0 [email protected]\n’ > /usr/bin/dropbox$ chmod +x /usr/bin/dropboxexit|
That’s it. You may now use Dropbox as a backup option for Raspberry Pi!
Other Raspberry Pi Backup options
Frankly, you may find other variants for Raspbian backup.
For example, Backblaze. If looking through the Backblaze vs CrashPlan difference, the Backblaze offers a little bit more access opportunities as you can get the access to the files stored in the cloud from the mobile devices. But, at the same time, Backblaze includes only Windows or Mac client versions and that is a real obstacle for installing and using it on Raspberry Pi.
Another difference is that Backblaze have a 14-day trial period when you can use the cloud storage account for free and after the expiration date it’ll cost $5/month, while CrashPlan personal “For Home” service option is fully free.
Finally, Backblaze has got a special feature called “B2 cloud”, that can help developers to create the automatic cloud storage and backup via its API with full access both from desktop and mobile devices. It includes first 10Gb of a storage space for free which seems quite an attractive option to make sure if it fits all of your needs.
Another bright backup service provider is Elephant drive. Basically, it offers similar features, including automatic backup right into the cloud, web access both from desktop and mobile devices, secure sharing. But where the real difference is it is in the Elephant drive pricing plans.
It’s got a free option with 2Gb limited storage space. Concerning the paid ones, there is a choice between “Pro Plan” with $9.95 per month (includes 1,000 GB of storage space) and “Business” featuring $39.95/month (for 2,000 GB). There is a trial period consisting of 30 days of free access to any type of subscription plans. All of these peculiarities make Elephant drive quite interesting and attractive service to consider.
Of course, digging deeper, we can find other opportunities for building up backup for your files on Raspbian. Among them, there are such providers as SOS, Mozy, Livedrive, Acronis and lots of others. All of them look very alike, the only they differ with are their subscription plans, which means that all of them are paid services. If you are looking for the free backup opportunities, additionally to CrashPlan and Dropbox mentioned earlier in this article, you may consider using Google Drive as a cloud storage space.
We have learned lots of ways of saving your work files via Raspberry Pi backup. And it’s obvious that using ExaGear with powerful and up-to-date solutions such as Dropbox or CrashPlan can really save you time and money.
Also, note that with ExaGear Desktop use the tutorials above and work with other RM-based devices, such as Odroid, Banana Pi, Beagleboard, Cubox, Jetson, Cubieboard and etc.