||3 months ago|
|LICENSE||4 months ago|
|README.md||3 months ago|
|README_DE.md||3 months ago|
|imagebackup.sh||4 months ago|
What is the purpose of "imagebackup"?
- creates via
dda full copy of you Raspberry Pi´s SD card as a complete backup
- stores the backup on an external storage device
- shrinks the image with Drewsif´s pishrink.sh to avoid any problems with "incorrect" sizes of SD cards (🔗 https://github.com/Drewsif/PiShrink)
- zip shrinked image via
gizpto save storage space on external storage device
- removes the now "useless"
ddbackup and the shrinked image
- 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
- shrinking via
- zipping via
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 (
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"?
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
Secondly, make sure your external storage device can be mounted without any problems 🔗 Raspberry Pi Image verkleinern mit pishrink
Thirdly, you have to use PiShrink 🔗 https://github.com/Drewsif/PiShrink
Can the whole process get automatized?
Of course, you can automatize the hole process by setting up a cron job to call imagebackup.sh.
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
because the script gets updated automatically by imagebackup.sh. 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.
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.
- Create a directory for your custom scripts on you Pi`s hard drive.
sudo mkdir /etc/scripts cd /etc/scripts
- 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 https://github.com/Drewsif/PiShrink.git
- Change directory
- Set script permissions for pishrink.sh
sudo chown root:root pishrink.sh sudo chmod 0600 pishrink.sh sudo chmod +x pishrink.sh
- Copy the imagebackup.sh on you local hard drive
- Clone the imagebackup repository from codeberg.org on your Pi´s hard drive
sudo clone https://codeberg.org/strobelstefan.org/imagebackup.git
⚠️ 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.
- Adjust the variables at the top of the script according your needs.
sudo nano /etc/scripts/imagebackup/imagebackup.sh
# Storage device as defined in your /etc/fstab. mountpoint='/mnt/usbbackup/' # Path were the image of your SD card should be saved to STORAGEPATH="/mnt/usbbackup/nextcloud/images" # Location of Nextcloud Installation NEXTCLOUDINSTALLATION="/var/www/html/nextcloud" # Location of PiShrink script pishrink.sh PISHRINK="/etc/scripts/PiShrink" # Location of imagebackup IMAGEBACKUP="/etc/scripts/imagebackup" # Location of image backup script IMAGESCRIPT="/etc/scripts/imagebackup/imagebackup.sh" # Image name IMAGENAME="nextcloud" # E-Mail Address For Messages EMAIL="firstname.lastname@example.org" # E-Mail Address for sending out backup script EMAILIMAGESCRIPT="email@example.com" #Log File location and name LOGFILE="/var/log/imagebackup.log"
- Adjust permissions for imagebackup.sh
sudo chown root:root imagebackup.sh sudo chmod 0600 imagebackup.sh sudo chmod +x imagebackup.sh
The runtime of the script can be very very very long. So it is highly recommended to use
screento avoid any interruptions.
cd /etc/scripts screen # This is optional sudo ./imagebackup.sh
- Setup a cron
# imagebackup # At 01:00 on Wednesday 0 01 * * 3 /bin/bash /etc/scripts/imagebackup/imagebackup.sh # At 01:00 on Sunday. 0 01 * * 0 /bin/bash /etc/scripts/imagebackup/imagebackup.sh
If you would like to call the script on another time maybe crontab guru is helpful: 🔗 https://crontab.guru
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:
- Use rsync to put your data on a total different storage which is physically separated from your Raspberry Pi. In this blog post I show you how to backup a hole Nextcloud instance via rsync 🔗 Datensicherung für die Nextcloud mit rsync
- Use BorgBackup to put your data encrypted on a total different storage which is physically separated from your Nextcloud. In this blog post I show you hot to set it up 🔗 Datensicherung für die Nextcloud mit BorgBackup
- You can also use your FRITZ!Box as an external storage 🔗 AVM NAS als Festplatte bei Raspberry Pi als Festplatte mounten
Do you find the templates helpful, then feel free to buy me a coffee ☕ 😊 😎
Du findest meine Vorlagen hilfreich, dann kannst du mir gerne einen Kaffee ausgeben ☕ 😊 😎
You can find more exciting articles on IT topics on my website www.strobelstefan.org
There you can find more articles about Nextcloud and the popular Raspberry Pi:
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.