├── README.md └── backup.sh /README.md: -------------------------------------------------------------------------------- 1 | # Do you like Smart Home? 2 | 3 | Take a look at https://smarthome-kompendium.com - the best place to get informed! 4 | 5 | # RaspberryBackup 6 | Create a backup of the raspberry pi on a NAS using cronjobs 7 | 8 | This script was created by raspberry.tips (https://raspberry.tips/raspberrypi-einsteiger/raspberry-pi-datensicherung-erstellen). 9 | Modified by Lukas Knoeller to send mails. 10 | 11 | More information available here: https://hobbyblogging.de/raspberry-pi-vollautomatisch-sichern (german) 12 | 13 | # Important information 14 | 15 | Please keep in mind that removing your sd-cart from the Pi is a much better solution to create an image of it. There are many tools to create an image from an sd-card. 16 | -------------------------------------------------------------------------------- /backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Quelle des Skripts: https://raspberry.tips/raspberrypi-einsteiger/raspberry-pi-datensicherung-erstellen 3 | # Modifiziert von Lukas Knoeller (hobbyblogging.de) 4 | # Vor Nutzung bitte die Pfade entsprechend anpassen und die E-Mailadresse richtig setzen 5 | # Zum Senden von E-Mails auf dem Raspberry kann das Paket ssmtp genutzt werden 6 | 7 | #Festplatte einbinden 8 | mount -t cifs -o user=USERNAME,password=PASSWORD,rw,file_mode=0777,dir_mode=0777 //IP/FREIGABE /mnt/nas 9 | 10 | #Variablen 11 | BACKUP_PFAD="/mnt/nas/Backup" 12 | BACKUP_ANZAHL="5" 13 | BACKUP_NAME="Sicherung" 14 | 15 | #Backup erstellen 16 | dd if=/dev/mmcblk0 of=${BACKUP_PFAD}/${BACKUP_NAME}-$(date +%Y%m%d).img bs=1MB 17 | 18 | #Alte Sicherung löschen 19 | pushd ${BACKUP_PFAD}; ls -tr ${BACKUP_PFAD}/${BACKUP_NAME}* | head -n -${BACKUP_ANZAHL} | xargs rm; popd 20 | 21 | #Festplatte auswerfen 22 | umount /mnt/nas 23 | 24 | #Info versenden 25 | to="mail@example.com" 26 | servername="NAME or IP" 27 | mail -s "Backup Skript" -t $to <<< "Der Server ($servername) hat eben das Backup-Skript ausgeführt." 28 | --------------------------------------------------------------------------------