floss:config_ubuntu_server_rpi3

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
Prochaine révisionLes deux révisions suivantes
floss:config_ubuntu_server_rpi3 [2020/12/26 20:57] villersdfloss:config_ubuntu_server_rpi3 [2024/01/22 12:12] villersd
Ligne 138: Ligne 138:
     * sudo apt-get upgrade     * sudo apt-get upgrade
     * sudo apt-get dist-upgrade     * sudo apt-get dist-upgrade
 +  * [[https://www.howtoraspberry.com/2020/04/disable-ipv6-on-raspberry-pi/|How to Really Disable IPv6 on Raspberry PI – How to Raspberry]]] → désactiver IPv6 en cas de trafic visible
 +
  
  
Ligne 176: Ligne 178:
  
 <code backup.sh> <code backup.sh>
-#!/bin/sh+#!/bin/bash
 THESITE="wiki01" THESITE="wiki01"
 THEDB="dbname" THEDB="dbname"
Ligne 187: Ligne 189:
 #tar -czf ~/${THESITE}backups/files/sitebackup_${THESITE}_${THEDATE}.tar.gz /var/www/html/${THESITE} #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} tar -czf /media/usb/sauvegardes/sitebackup_${THESITE}_${THEDATE}.tar.gz /var/www/html/${THESITE}
-# éliminer les fichier vieux de plus de 5 jours → À RETESTER !! +# éliminer les fichier vieux de plus de 5 jours 
-#find /backups/files/site* -mtime +5 -exec rm {} \; +find ~/backups/files/site* -mtime +5 -exec rm {} \; 
-#find /backups/files/db* -mtime +5 -exec rm {} \;+find ~/backups/files/db* -mtime +5 -exec rm {} \;
 </code> </code>
  
-Version après élimination d'erreurs :+Version après élimination d'erreurs, et sans effacement :
  
 <code backup.sh> <code backup.sh>
Ligne 202: Ligne 204:
 </code> </code>
  
 +Test du backup :
 +<code>
 +./backup.sh
 +</code>
 +
 +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 :
 +
 +<code>
 +# 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
 +
 +</code>
 +
 +Here's how the script works:
 +  - Set the DIR variable to the directory you want to clean up.
 +  - Use the date command to calculate the cutoff date. This will be 8 days ago from today.
 +  - Loop through each file in the directory using a for loop.
 +  - Check if the file is a regular file (-f) and if its modification time is older than the cutoff date. If it is not, then skip to the next file.
 +  - If the file's modification time is older than the cutoff date, check if the file's date is the first day of the month. If it is, then skip to the next file.
 +  - If the file's date is not the first day of the month, then delete the file using the rm command.
 +
 +Références sur les formats de date :
 +  * [[https://www.shell-tips.com/linux/how-to-format-date-and-time-in-linux-macos-and-bash/#gsc.tab=0|How To Format Date and Time in Linux, macOS, and Bash?]]
 +  * [[https://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/|How To Format Date For Display or Use In a Shell Script - nixCraft]]
 +  * [[https://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script|bash - YYYY-MM-DD format date in shell script - Stack Overflow]]
 +  * [[https://phoenixnap.com/kb/linux-date-command|Date Command in Linux: How to Set, Change, Format and Display Date]]
 +
 +Références sur les scripts de backup
 +  * [[https://iq.opengenus.org/automated-backup-in-linux-using-shell-scripting-and-crontab-scheduler/|Automated Backup in Linux using Shell Scripting and Crontab Scheduler]]
 +  * [[https://medium.com/@fotios.floros/linux-backup-script-1722cc9c2bf6|Linux Backup Script. This tutorial explains how to create a… | by Fotios Floros | Medium]]
 +  * [[https://github.com/gzachos/backup-script/blob/master/backup.sh|backup-script/backup.sh at master · gzachos/backup-script · GitHub]]
 +  * [[https://stackoverflow.com/questions/73658439/how-can-write-bash-script-to-get-backup|linux - how can write bash script to get backup - Stack Overflow]]
 +  * [[https://unix.stackexchange.com/questions/347822/simple-bash-script-for-backing-up-and-deleting-directories|linux - Simple bash script for backing up and deleting directories - Unix & Linux Stack Exchange]]
  
  
  • floss/config_ubuntu_server_rpi3.txt
  • Dernière modification : 2024/04/16 09:34
  • de villersd