Last active
October 8, 2021 15:13
-
-
Save jlstanus/0fba2e7725548dd7611116c0ef6dc36b to your computer and use it in GitHub Desktop.
RPI Backup
This file contains hidden or 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 | |
# | |
# Automate Raspberry Pi Backups | |
# Inspired from https://raw.githubusercontent.com/kallsbo/BASH-RaspberryPI-System-Backup/master/system_backup.sh | |
# Kristofer Källsbo 2017 www.hackviking.com | |
# | |
# Usage: system_backup.sh {path} {days of retention} | |
# | |
# Below you can set the default values if no command line args are sent. | |
# The script will name the backup files {$HOSTNAME}.{YYYYmmdd}.img | |
# When the script deletes backups older then the specified retention | |
# it will only delete files with it's own $HOSTNAME. | |
# | |
# Declare vars and set standard values | |
backup_path=/mnt/backup/ | |
retention_days=3 | |
# Check that we are root! | |
if [[ ! $(whoami) =~ "root" ]]; then | |
echo "" | |
echo "**********************************" | |
echo "*** This needs to run as root! ***" | |
echo "**********************************" | |
echo "" | |
exit | |
fi | |
# Check to see if we got command line args | |
if [ ! -z $1 ]; then | |
backup_path=$1 | |
fi | |
if [ ! -z $2 ]; then | |
retention_days=$2 | |
fi | |
# Create trigger to force file system consistency check if image is restored | |
touch /boot/forcefsck | |
# Perform backup | |
dd if=/dev/mmcblk0 of=$backup_path/$HOSTNAME.$(date +%Y%m%d).img bs=1M | |
# Remove fsck trigger | |
rm /boot/forcefsck | |
# Delete old backups | |
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Configuration
Nom d'hôte ou ip: ip du client (rpi) 192.168.1.10
Privilège: lecture/écriture
Squash: mappage de tous les utilisateurs
Sécurité: sys
Cocher: activer le mode asucnhrone, permettre la connexion à partir des portsnnon priviléiés, permettre à des utilisateurs d'accéder aux sous dossier, etc
Vérifier
192.168.1.xxx:/volume1/8_BackUPs/rpi /mnt/backup nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
0 3 * * * /mnt/backup/system_backup.sh