Skip to content

Create a backup using the DD command. Scripts to make life easier.

Notifications You must be signed in to change notification settings

iotshelnik/Raspberry-DD-Backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Raspberry-DD-Backup

Create a backup using the DD command. Scripts to make life easier.


How to:

Server side

The original "pishrink.sh" script is at github page.

Installation

wget https://raw.githubusercontent.com/iotshelnik/Raspberry-DD-Backup/main/pishrink.sh
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin

Usage

You may read about usage at original "pishrink.sh" script page: Drewsif / PiShrink .

Note: Script is modified to delete some additional directories and to compress image after shrinking with gzip (it is -p and -z keys) as the default option. Even if you are not using these keys in command.

As the result, you will have the compressed image (*.img) with will take less space to store. It will have format *.img.gz.

Raspberry Pi side:


Check that Python3 version is 3.6 ot highter.

Check that NFS server IP is accessible.


Usage

wget https://raw.githubusercontent.com/iotshelnik/Raspberry-DD-Backup/main/RPi-Backup.py
sudo python3 RPi-Backup.py --nfs '172.28.10.100:/share-dir'

Follow on-screen instructions.

After Image is created unmount NFS share:

sudo umount /Backups

Example for RPi-Backup.py script

pi@raspberry:~ $ sudo python3 RPi-Backup.py --nfs '172.28.10.100:/share-dir'
The NFS share to mount is: 172.28.10.100:/share-dir 
The hostname is: raspberry
Check|Create the directory for backup: 
 /Backups/raspberry/
The date is: 05032022-11-39
The '/boot' directory is stored at: /dev/mmcblk0p1 subdrive.


The block devices presented in this system are:

NAME      FSTYPE  SIZE TYPE MOUNTPOINT
mmcblk0            29G disk 
mmcblk0p1 vfat    256M part /boot
mmcblk0p2 ext4   28.8G part /

Select with device is boot drive with OS?
[ 1 - /dev/mmcblk0 | 2 - /dev/sda ] : 1
The "/dev/mmcblk0" will be as a source to copy from!

Sectors count: 60868608
Physical block size: 512
Run the command below to create the backup image from SD card with OS to the NFS storage:

sudo dd if=/dev/mmcblk0 of=/Backups/raspberry/raspberry_05032022-11-39.img bs=4096 count=7608576 status=progress conv=fsync
Or use command below, but ansure that the "pv" is installed !
sudo dd if=/dev/mmcblk0 bs=4096 count=7608576 | pv | sudo dd of=/Backups/raspberry/raspberry_05032022-11-39.img

To run in backgroud use next command:
sudo dd if=/dev/mmcblk0 of=/Backups/raspberry/raspberry_05032022-11-39.img bs=4096 count=7608576 &

Restore

To restore the image file you may use the official "Raspberry Pi Imager" or use, as an example, the command below from the shell:

gunzip -c /NFSShare/path/to/image/file.img.gz | dd of=/dev/{sda|mmcblk0} conv=sync,noerror bs=4k status=progress

Example

$ sudo gunzip -c /Backups/raspberry/raspberry_05032022-11-39.img.gz | dd of=/dev/sda conv=sync,noerror bs=4k status=progress

1008295+1 records in
1008296+0 records out
4129980416 bytes (4.1 GB, 3.8 GiB) copied, 147.894 s, 27.9 MB/s

About

Create a backup using the DD command. Scripts to make life easier.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published