Erstellen eines komplettes Backups der gesamten SD-Karte eines Raspberry Pis.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9.8 KiB


🇩🇪 README auf deutsch lesen

What is the purpose of "imagebackup"?

The script

  1. creates via dda full copy of you Raspberry Pi´s SD card as a complete backup
  2. stores the backup on an external storage device
  3. shrinks the image with Drewsif´s to avoid any problems with "incorrect" sizes of SD cards ​(🔗
  4. zip shrinked image via gizp to save storage space on external storage device
  5. removes the now "useless" ddbackup and the shrinked image
  6. sends status via e-mail to admin

What Raspberry Pi model should I use?

The script can consume a lot of resources of your Raspberry Pi especially for

  • creating backup via dd
  • shrinking via pishrink
  • zipping via gzip

At least a Raspberry Pi model 3 is required even better a Raspberry Pi 4. The newest model has more memory power which will speed up the whole process significantly.

The script and a running Nextcloud (no logged in users) consumes the following memory of a Raspberry Pi:

Mem ~ 350 to 400 M of 3.74G

The load on the CPU is almost nothing It varies between all four cores and it is between 5 to 25%.

No worries, if you have an older Raspberry Pi you can use the process to create a full backup of your Pi, too. Just skip the shrink and zip process on it. Put the ddbackup on an external storage and run the other two operations (pishrink& gzip) on a "stronger" hardware, e.g. newer Raspberry Pi, laptop, server, virtual box, etc.

Even this process which is not very handy can be atomized so it is more user friendly. Please have a look at "More features that can be easily used with imagebackup" to get inspired. 😊

What is required to use "imagebackup"?

  1. Firstly, you have to have a working Mail Transfer Agent (MTA) like Postfix and an e-mail client like mutt installed on you server. Of course you find a detailed manual how to setup both on my website: 🔗 E-Mail-Versand für den Raspberry Pi konfigurieren

  2. Secondly, make sure your external storage device can be mounted without any problems 🔗 Raspberry Pi Image verkleinern mit pishrink

  3. Thirdly, you have to use PiShrink 🔗

Can the whole process get automatized?

Of course, you can automatize the hole process by setting up a cron job to call

Are there any security issues?

To be honest, there can be some. But the issues are not really related to the script itself it is more related to the script permissions and you server admins.

The script requires some high permissions,

  • root permissions to mount external storage devices and
  • root permissions to call imagebackup

To achieve both that we have to use sudo crontab -e.

The high risk is therefore, if an user gains write access to the script, he/she can execute unauthorized commands though the crontab.

Please double check

  • the permissions of the script
  • users who can use sudo or root on your system are setup correctly
  • that personalized accounts for your admins are in use

If you are interested in securing your system in a good way with hardware tokens and certificates, please have a close look at the YubiKey category on my website


Despite the concerns mention above you have to trust

  • PiShrink

because the script gets updated automatically by If you have an uneasy feeling about it uncomment the auto-upgrade function in the script. So you can check the script manually before you upgrade it.


I use gitto clone the whole PiShrink repository from GitHub in my local hard drive to easily update the script via script. All my scripts are located in one folder and organized in sub-folders which makes it very easy to maintain them.

  1. Create a directory for your custom scripts on you Pi`s hard drive.
sudo mkdir /etc/scripts
cd /etc/scripts
  1. Clone the PiShrink repository on your local hard drive into the newly created folder. This command will create a new sub-folder called PiShrink which contains all files of the GitHub repository.
sudo clone
  1. Change directory
  1. Set script permissions for
sudo chown root:root
sudo chmod 0600
sudo chmod +x
  1. Copy the on you local hard drive
cd /etc/scripts
  1. Clone the imagebackup repository from on your Pi´s hard drive
sudo clone

⚠️ The repository WON`T get updated automatically. We only copy the current version from Codeberg on the Raspberry Pi´s . Auto update for imagebackup ist not recommended because your variables at the top of the script will get over written.

  1. Adjust the variables at the top of the script according your needs.
 sudo nano /etc/scripts/imagebackup/
# Storage device as defined in your /etc/fstab.

# Path were the image of your SD card should be saved to

# Location of Nextcloud Installation

# Location of PiShrink script

# Location of imagebackup

# Location of image backup script

# Image name

# E-Mail Address For Messages

# E-Mail Address for sending out backup script

#Log File location and name
  1. Adjust permissions for
sudo chown root:root
sudo chmod 0600
sudo chmod +x
  1. Run script

    The runtime of the script can be very very very long. So it is highly recommended to use screen to avoid any interruptions.

cd /etc/scripts
screen # This is optional
sudo ./
  1. Setup a cron
# imagebackup
# At 01:00 on Wednesday
0 01 * * 3 /bin/bash /etc/scripts/imagebackup/
# At 01:00 on Sunday.
0 01 * * 0 /bin/bash /etc/scripts/imagebackup/

​ If you would like to call the script on another time maybe crontab guru is helpful: ​ 🔗

More features that can be easily used with imagebackup

There are many other ways to store your exports on another physically separated device, too. Here are some examples:


Do you find the templates helpful, then feel free to buy me a coffee Donate 😊 Donate 😎

Du findest meine Vorlagen hilfreich, dann kannst du mir gerne einen Kaffee ausgeben Donate 😊 Donate 😎

You can find more exciting articles on IT topics on my website

There you can find more articles about Nextcloud and the popular Raspberry Pi:

⚠️ Disclaimer


The working methods described here are based on my personal experience and my personal thought processes. I do not guarantee the results; trying out and implementing the described procedures is entirely at your own risk and responsibility.

Therefore, please make a backup before making any changes to your system or configuration so that you can restore it if the worst comes to the worst.


Die hier geschilderten Arbeitsweisen basieren auf meiner persönlichen Erfahrung und meinen persönlichen Gedankengängen. Ich übernehme keine Garantie für die Resultate; Ausprobieren und Implementieren der beschriebenen Vorgehensweisen erfolgt ausschließlich auf eigene Verantwortung und Gefahr.

Bitte erstellt deshalb vor jeder Änderung an eurem System oder Konfiguration ein Backup, damit ihr im Fall der Fälle eine Wiederherstellung durchführen könnt.