I had a SD-card crash for the first time on my RPi recently so I had to recover. I draw some experience from this exercise which I would like to share.
For a situation like this I had been making backups: once a week a total system backup and a daily backup of the CumulusMX directory tree. The backup was saved to my NAS and I deleted the CMX backups older than a week and system backups older than a month. So I thought to restore the most recent system backup and then overwrite CMX with the most recent CMX backup. And - don't be surprised - the system backup failed to restore. Why? I don't know. A test restore some time ago worked.
So, what to do? I decided to install a complete new Raspbian with the new Raspberry Pi Imager.
Piece of cake. Create the SSH file on /boot (to have the headless boot) and create the (wpa_supplicant.conf for the WiFi). Personally I also make an entry for a fixed IP address as well. Then I ran my UpdateSystem script (I have some scripts which I also backup separately) to be up to date with everything and install:
- Mono complete (required)
- lshw (required for CumulusUtils)
- zip (required for backing up)
- reinstate the crontab things you want to do (including the backup)
Then I unzip my Cumulus Backup on the PC and copy it to the RPi, copy the systemd script to the systemd directory (adjust directory).
Done. Within 30 minutes I had manually restored my RPi system. I am done with the full system backup which takes almost an hour and which does not restore.
It is a very simple attitude towards crashes without complex backup systems: just reinstall the system
Conclusion: just backing up the CMX directory is enough.
The advantage is that once in a while you need to restore your system and it keeps your knowledge up to date reviewing everything
So here is the backup script I use which appeared very useful. If you don't have a NAS, adjust to wherever you want to backup.
It is ran through crontab, output in a logfile.
Code: Select all
#!/bin/bash -v
#
#######################################################################################################################
#
# Create and restore a backup of a Raspberry running raspbian
# Need to run as root
#
#Usage: pause "Press [return] to continue---"
function pause(){
read -p "$*"
}
# Goto the /home directory and stop CumulusMX
cd /home
systemctl stop cumulusmx
DATE=$(date +%Y%m%d-%H%M%S)
HOSTNAME=$(hostname)
NL=$'\n'
CURRENT_DIR=$(pwd)
FILENAME="$DATE"'-CumulusMX.zip'
BCKPDIR="/mnt"
date
echo "Creating CumulusMX backup in "$FILENAME
if ( /sbin/showmount -e 192.*.*.* )
then
echo "The NAS is online!"
if ( mount -t nfs -o defaults -v 192.*.*.*:/volume1/Backups/Meteo $BCKPDIR )
then
echo "Mount succesful"
echo "Starting the zip/backup operation. Timing:"
time zip -r -q $BCKPDIR/"$FILENAME" CumulusMX
echo "Starting the find/delete operation. Timing:"
time find $BCKPDIR/ -type f -name '*CumulusMX.zip' -mtime +7 -exec rm '{}' \;
echo "Starting the unmounting operation. Timing:"
time umount -v $BCKPDIR
echo "Backup CumulusMX succesfully completed"
fi
else
echo "The NAS is not online, cumubackup failed, script halted!"
fi
systemctl start cumulusmx
echo "Backup CumulusMX is finished"
date
Code: Select all
#!/bin/bash
#
#######################################################################################################################
#
# Update the raspbian system and installed apps
# Need to run as root
#
# nov 2019: Upgrade for RAspbian buster
#
apt update
apt full-upgrade
apt autoremove
apt clean
#apt-get purge libmono* cli-common mono-runtime
#apt install apt-transport-https dirmngr gnupg ca-certificates
#apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
#echo "deb https://download.mono-project.com/repo/debian stable-raspbianbuster main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
#apt update
#apt-get update && sudo apt-get upgrade
#apt-get install mono-complete
#apt autoremove