admin:infrastructure:backup
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| admin:infrastructure:backup [2021/01/02 17:47] – [Scripts de pre hooks] fpoulain | admin:infrastructure:backup [2026/03/03 16:48] (Version actuelle) – Correction typographique fhenry2 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Paquet Debian ====== | ====== Paquet Debian ====== | ||
| - | Le backup | + | La sauvegarde |
| + | On décrit ici les points essentiels du paquet à défaut de publier le dépôt, ainsi que la configuration du contrôle d' | ||
| ===== Aspects backup ===== | ===== Aspects backup ===== | ||
| Ligne 7: | Ligne 8: | ||
| ==== Script de backup ==== | ==== Script de backup ==== | ||
| - | C'est fournis par [[https:// | + | C'est fournis par [[https:// |
| - | On y adjoint une configuration dans ''/ | + | On y adjoint une configuration dans ''/ |
| <code yaml / | <code yaml / | ||
| Ligne 25: | Ligne 26: | ||
| - '/ | - '/ | ||
| - '/ | - '/ | ||
| - | - '/ | ||
| - '/ | - '/ | ||
| - | - '/ | ||
| repositories: | repositories: | ||
| - | - ' | + | - 'ssh://backup@backup.chapril.org/ |
| storage: | storage: | ||
| Ligne 52: | Ligne 51: | ||
| - for file in / | - for file in / | ||
| - echo " | - echo " | ||
| + | - borgmatic info --archive latest --json | ||
| on_error: | on_error: | ||
| - echo " | - echo " | ||
| Ligne 63: | Ligne 63: | ||
| ==== Entrée Systemd ==== | ==== Entrée Systemd ==== | ||
| - | On déclenche avec un timer systemd | + | On déclenche avec un compteur de Systemd |
| - | < | + | < |
| [Unit] | [Unit] | ||
| Description=Run borgmatic backup | Description=Run borgmatic backup | ||
| Ligne 81: | Ligne 81: | ||
| </ | </ | ||
| - | < | + | < |
| [Unit] | [Unit] | ||
| Description=borgmatic backup | Description=borgmatic backup | ||
| Ligne 262: | Ligne 262: | ||
| exit 0 | exit 0 | ||
| + | </ | ||
| + | |||
| + | ==== Rsyslog ==== | ||
| + | |||
| + | <code - / | ||
| + | if $programname == ' | ||
| + | & stop | ||
| </ | </ | ||
| ==== Log rotate ==== | ==== Log rotate ==== | ||
| - | < | + | < |
| - | /var/log/backup.log { | + | /var/log/borgmatic.log |
| - | weekly | + | { |
| - | | + | |
| - | | + | |
| - | | + | compress |
| - | | + | missingok |
| - | notifempty | + | notifempty |
| - | create 644 root root | + | |
| } | } | ||
| </ | </ | ||
| - | ===== Configuration de l'hote ===== | + | ===== Configuration de l'hôte ===== |
| - | C'est surtout du ssh. | + | C'est surtout du SSH. |
| - | < | + | < |
| command=" | command=" | ||
| command=" | command=" | ||
| Ligne 290: | Ligne 296: | ||
| ===== Configuration du monitoring ===== | ===== Configuration du monitoring ===== | ||
| - | On a un script qui parse sur chaque machine le log de backup | + | On a un script qui //parse// sur chaque machine le //log// de sauvegarde |
| - | <code python / | + | <code python / |
| - | # | + | # |
| - | # -*- encoding: | + | |
| - | import datetime, os, re, locale | + | import datetime, itertools, os, re |
| - | today= datetime.datetime.now () | + | now = datetime.datetime.now(datetime.timezone.utc) |
| - | max_backup_delay = datetime.timedelta (1, 7200) | + | max_backup_delay = datetime.timedelta(1, |
| - | def last_backup | + | def get_name(match): |
| - | | + | return |
| - | logs_ok = re.findall (r'^([ a-zéûA-Z:, | + | |
| - | print "Last backup : " + logs_ok | + | |
| - | try: | + | |
| - | | + | |
| - | except: | + | |
| - | locale.setlocale(locale.LC_ALL, | + | |
| - | return datetime.datetime.strptime | + | |
| + | def check_backup(filename): | ||
| + | with open(filename) as f: | ||
| + | logs = f.read() | ||
| + | mixed_statuses = list(re.finditer(r' | ||
| + | for name, statuses in itertools.groupby(sorted(mixed_statuses, | ||
| + | last = sorted(statuses, | ||
| + | print(' | ||
| + | last_date = datetime.datetime.fromisoformat(last.group(' | ||
| + | last_status = last.group(' | ||
| + | if last_status != ' | ||
| + | failure.append(name) | ||
| + | |||
| + | failure = [] | ||
| try: | try: | ||
| - | | + | |
| - | except: | + | except |
| - | | + | |
| - | if today - last_backup_date < max_backup_delay: | + | if failure: |
| + | exit (1) | ||
| + | else: | ||
| exit (0) | exit (0) | ||
| - | else: | ||
| - | exit (1) | ||
| </ | </ | ||
| - | Et la conf icinga2 | + | Et la configuration pour Icinga 2 : |
| - | < | + | < |
| object CheckCommand " | object CheckCommand " | ||
| - | command = [ PluginDir + "/check_backup" ] | + | command = [ " |
| } | } | ||
| Ligne 339: | Ligne 350: | ||
| ===== Aspects contrôle d' | ===== Aspects contrôle d' | ||
| - | On contrôle directement chaque nuit sur la machine où les backups | + | On contrôle directement chaque nuit sur la machine où les sauvegardes |
| ==== Script de contrôle ==== | ==== Script de contrôle ==== | ||
| Ligne 381: | Ligne 392: | ||
| ==== Entrée Cron ==== | ==== Entrée Cron ==== | ||
| - | < | + | < |
| 00 4 * * * root bash / | 00 4 * * * root bash / | ||
| </ | </ | ||
| Ligne 387: | Ligne 398: | ||
| ==== Log rotate ==== | ==== Log rotate ==== | ||
| - | < | + | < |
| / | / | ||
| weekly | weekly | ||
| Ligne 401: | Ligne 412: | ||
| ==== Configuration du monitoring ==== | ==== Configuration du monitoring ==== | ||
| - | On a un script qui parse sur la machine le log de check_backup : | + | On a un script qui parse sur la machine le log de '' |
| <code python __felicette__/ | <code python __felicette__/ | ||
| # | # | ||
| Ligne 432: | Ligne 443: | ||
| </ | </ | ||
| - | Et la conf icinga2 | + | Et la configuration pour Icinga 2 : |
| - | < | + | < |
| object CheckCommand " | object CheckCommand " | ||
| command = [ "/ | command = [ "/ | ||
| } | } | ||
| </ | </ | ||
| - | < | + | < |
| /* Backup checks */ | /* Backup checks */ | ||
| apply Service "Check Backup " { | apply Service "Check Backup " { | ||
admin/infrastructure/backup.1609609676.txt.gz · Dernière modification : 2021/01/02 17:47 de fpoulain
