Showing posts with label pi raspberry pi backup. Show all posts
Showing posts with label pi raspberry pi backup. Show all posts

Wednesday 5 May 2021

What's the easiest way to backup your raspberry pi to an image? [Answered]

 This is the simplest way to backup your pi.

backup your raspberry pi
Backup your raspberry pi

(Photo by Markus Winkler on Unsplash)

Backing up your raspberry pi is fairly straightforward. Here's my quick and easy guide. Script by Mark at projektor.co.uk

Requirements

Raspberry pi

USB drive for backup


Instructions

Assuming you have no other drives connected to your pi.

Insert a USB pen drive into your raspberry pi.

Issue the following command:

wget -c https://raw.githubusercontent.com/markcity/pibackup/a2fd2b9697a61a6e3f8c8b60546ac7a54abe8041/makeimage.sh;bash ./makeimage.sh

When completed you will have an image of your pi on the USB stick.

You can safely remove the USB stick.


Want to restore the image?

Use Win32DiskImager - download link https://sourceforge.net/projects/win32diskimager/

 

For reference, the script contains the following lines.

#create a variable today using the current date in the format Year-Month-Date
today=$(date +"%Y-%m-%d")
#set up a folder to map to the usb drive
sudo mkdir /media/usb
#make the new folder owned / writeable by the user
sudo chown -R pi:pi /media/usb
#map / mount the usb stick at the folder /media/usb
sudo mount /dev/sda1 /media/usb -o uid=pi,gid=pi
#just in case, give the raspberry pi ability to write to NTFS file format
sudo apt-get install ntfs-3g
#use dd command to backup the 'mmc' - SD card to a file
sudo dd if=/dev/mmcblk0 of=/media/usb/pi_img_${today}.img bs=1M
#unmount the USB card so it can be 
sudo umount /dev/sda1