sudo snap install rpi-imager
# /etc/netplan/50-cloud-init.yaml netplan configuration file network: ethernets: eth0: dhcp4: true optional: true version: 2 # wifi setup informations wifis: wlan0: optional: true access-points: "SSID": password: "*******" dhcp4: no addresses: [192.168.1.251/24] gateway4: 192.168.1.1 nameservers: addresses: [192.168.1.1, 8.8.8.8]
À ce stade, le Raspberry Pi est connecté par wifi avec l'adresse IP 192.168.1.251
Le wiki est pré-configuré et (presque) opérationnel ! Réglages complémentaires de la configuration via le menu d’administration - “Paramètres de configuration” :
sudo fsck -y /dev/mmcblk0p1
sudo fsck -y /dev/mmcblk0p2
#!/bin/bash
THESITE="wiki01"
THEDB="dbname"
THEDBUSER="dbuser"
THEDBPW="dbpwd"
THEDATE=`date +%F-%T`
# backup de la base de données NON UTILISÉ
#mysqldump -u $THEDBUSER -p${THEDBPW} $THEDB | gzip > ~/${THESITE}backups/files/dbbackup_${THEDB}_${THEDATE}.bak.gz
# backup des fichiers du site
#tar -czf ~/${THESITE}backups/files/sitebackup_${THESITE}_${THEDATE}.tar.gz /var/www/html/${THESITE}
tar -czf /media/usb/sauvegardes/sitebackup_${THESITE}_${THEDATE}.tar.gz /var/www/html/${THESITE}
# éliminer les fichier vieux de plus de 5 jours
find ~/backups/files/site* -mtime +5 -exec rm {} \;
find ~/backups/files/db* -mtime +5 -exec rm {} \;
Version après élimination d'erreurs, et sans effacement :
#!/bin/sh
THESITE="wiki01"
THEDATE=`date +%F-%H%M%S`
# backup des fichiers du site
tar -czf /media/usb/sauvegardes/sitebackup_${THESITE}_${THEDATE}.tar.gz /var/www/html/${THESITE}
Test du backup :
./backup.sh
Part of bash (version >=4.2) script to remove files in a given directory, older than 8 days, but leave files dated the first day of each month :
# Set the directory to clean up
DIR="~/backups/files/"
# Calculate the cutoff date
CUTOFF=$(date -d "8 days ago" +%s)
# Loop through the files in the directory
for FILE in "$DIR"/*
do
# Check if the file is older than 8 days
if [[ -f "$FILE" && $(date -r "$FILE" +%s) -lt $CUTOFF ]]
then
# Check if the file's date is the first day of the month
if [[ $(date -r "$FILE" +%d) -eq 01 ]]
then
echo "Skipping $FILE"
else
echo "Deleting $FILE"
rm "$FILE"
fi
fi
done
Here's how the script works:
Références sur les formats de date :
Références sur les scripts de backup