Last active
March 7, 2021 19:44
-
-
Save bsoufflet/e362c72a8aae979ae9c8 to your computer and use it in GitHub Desktop.
RaspberryPi / BananaPi SD Clone to Freebox V6 or to any mounted drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Stop all Jeedom services then backup the SD card to the Freebox V6 HD | |
# then reboot the RaspberryPi/BananaPi | |
# | |
# === Sources === | |
# - https://forum.jeedom.fr/viewtopic.php?f=66&t=4443 | |
# - http://doc.ubuntu-fr.org/freeboxv6 | |
# - http://www.domopi.eu/sauvegarde-de-la-carte-sd-du-raspberry-pi-sur-un-serveur-externe/ | |
# | |
# === Setup instructions === | |
# sudo apt-get install curl | |
# sudo apt-get install cifs-utils | |
# sudo mkdir /media/freebox/ | |
# sudo vi /etc/fstab | |
# add this line for a Freebox drive : | |
# //freebox-server.local/Disque\040dur /media/freebox cifs _netdev,username=freebox,password="freebox admin password",uid=1000,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0 | |
# or add this line for an NFS drive : | |
# 192.168.1.100:/volume1/Backup_Jeedom /mnt/Backup_NAS nfs rw,user 0 0 | |
# mount -a (just to check that it works) | |
# sudo chmod u+x CloneSD.sh | |
# sudo crontab -e | |
# 0 4 * * 3 sh /path/to/CloneSD.sh (every wednesday at 4am) | |
DATE=$(date +"%Y-%m-%d") | |
JeedomApiKey=MY-JEEDOM-API-KEY | |
BoxToClone=BananaPi | |
#Taille pour une carte de 4G avec gzip | |
SdImgSize=2032664576 | |
#FileName=SD-Backup_$BoxToClone\_$DATE.img #sans compression | |
FileName=SD-Backup_$BoxToClone\_$DATE.img.gz | |
File=/media/freebox/jeedom/$FileName | |
sudo service Jeedom stop && service nginx stop && service mysql stop | |
#sans compression : sudo dd if=/dev/mmcblk0 bs=4M of=$File && sync | |
sudo dd if=/dev/mmcblk0 bs=4M | sudo gzip -1 -| sudo dd of=$File && sync | |
FileStat=$(wc -c "$File" | cut -f 1 -d ' ') | |
if [ $? -eq 0 ]; then | |
if [ $FileStat -le $SdImgSize ]; then | |
Objet="($DATE) SD-Backup $BoxToClone : ERREUR" | |
Message="Taille du fichier $FileName incorrecte" | |
else | |
#taille OK | |
Objet="($DATE) SD-Backup $BoxToClone : OK" | |
Message="Clonage OK" | |
fi | |
else | |
if [ -e $File ]; then | |
sudo rm $File | |
fi | |
Objet="($DATE) SD-Backup $BoxToClone : ECHEC" | |
Message="Echec du Clonage : fichier inexistant." | |
fi | |
# Notify using Jeedom message system | |
/usr/bin/curl --netrc "http://localhost/jeedom/core/api/jeeApi.php?api=$JeedomApiKey&type=message&category=$Objet&message=$Message" | |
# notify using email | |
#echo "$Message" | mail -s "$Objet" AdresseDestinataire@gmail.com | |
sudo reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment