Technique/Sauvegardes.md

202 lines
6 KiB
Markdown
Raw Normal View History

2023-01-27 18:06:55 +01:00
Pour la sécurité en cas de besoins de restauration des données:
Nous avons des sauvegardes locales journalières des données et du système sur le volume `/mnt/backups/borgarchives` de 1 To avec avec [Borg App](https://github.com/YunoHost-Apps/borg_ynh), plus une sauvegarde journalière (aussi avec Borg App), chiffrée sur un serveur Yunohost auto-hébergé où est installé [Borg Server](https://github.com/YunoHost-Apps/borgserver_ynh) sur un disque dur de 2 To.
> ! Il est tout de même conseillé malgré toutes ces précautions aux utilisateurs qui ont des données sur Nextcloud (Cloud Linux07) de bien faire des sauvegardes de temps à autres. Nous ne pouvons pas garantir à 100% de ne jamais rien perdre, mais nous faisons tout notre possible pour éviter de risquer de perdre vos données.
Fichier de configuration des sauvegardes distantes vers BorgServer (machine auto-hébergé à l'adresse de l'association Linux07)
2024-09-07 14:39:33 +02:00
**/etc/yunohost/hooks.d/backup_method/05-borg_app (mise à jour 2024)**
2023-01-27 18:06:55 +01:00
```
2024-09-07 14:39:33 +02:00
#!/usr/bin/env bash
set -Eeuo pipefail
2023-01-27 18:06:55 +01:00
2024-09-07 14:39:33 +02:00
borg="/var/www/borg/venv/bin/borg"
app="borg"
2023-01-27 18:06:55 +01:00
2024-09-07 14:39:33 +02:00
BORG_PASSPHRASE="$(yunohost app setting "$app" passphrase)"
BORG_REPO="$(yunohost app setting "$app" repository)"
BORG_LOGGING_CONF="/var/www/borg/logging.conf"
if ssh-keygen -F "[domainborgserver.tld]:xxxx" >/dev/null ; then
2023-01-27 18:06:55 +01:00
BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=yes "
else
BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=no "
fi
do_need_mount() {
true
}
do_backup() {
export BORG_PASSPHRASE
2024-09-07 14:39:33 +02:00
export BORG_REPO
2023-01-27 18:06:55 +01:00
export BORG_RSH
2024-09-07 14:39:33 +02:00
export BORG_LOGGING_CONF
2023-01-27 18:06:55 +01:00
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
work_dir="$1"
name="$2"
2024-09-07 14:39:33 +02:00
size="$3"
description="$4"
2023-01-27 18:06:55 +01:00
set +e
2024-09-07 14:39:33 +02:00
if ! "$borg" list > /dev/null 2>&1; then
"$borg" init -e repokey
# human_size=`echo $size | awk '{ suffix=" KMGT"; for(i=1; $1>1024 && i < length(suffix); i++) $1/=1024; print int($1) substr(suffix, i, 1), $3; }'`
# Speed in Kbps
# speed=1000
# evaluated_time=$(($size / ($speed * 1000 / 8) / 3600))
echo "Hello,
2023-01-27 18:06:55 +01:00
2024-09-07 14:39:33 +02:00
Your first backup on $BORG_REPO is starting.
2023-01-27 18:06:55 +01:00
This is an automated message from your beloved YunoHost server." | /usr/bin/mail.mailutils -a "Content-Type: text/plain; charset=UTF-8" -s "[YNH] First backup is starting" "root"
fi
set -e
2024-09-07 14:39:33 +02:00
# About the {now} placeholder:
# https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
# In the archive name, you may use the following placeholders: {now}, {utcnow}, {fqdn}, {hostname}, {user} and some others.
"$borg" create --stats "::${name}-{now}" "$work_dir"
"$borg" prune --glob-archives "${name}-*" --list --keep-hourly 2 --keep-daily=7 --keep-weekly=8 --keep-monthly=12
2023-01-27 18:06:55 +01:00
# We prune potential manual backup older than 1 year
2024-09-07 14:39:33 +02:00
"$borg" prune --list --keep-within 1y
2023-01-27 18:06:55 +01:00
}
do_mount() {
export BORG_PASSPHRASE
2024-09-07 14:39:33 +02:00
export BORG_REPO
2023-01-27 18:06:55 +01:00
export BORG_RSH
2024-09-07 14:39:33 +02:00
export BORG_LOGGING_CONF
2023-01-27 18:06:55 +01:00
work_dir="$1"
name="$2"
2024-09-07 14:39:33 +02:00
size="$3"
description="$4"
"$borg" mount "::$name" "$work_dir"
2023-01-27 18:06:55 +01:00
}
work_dir="$2"
name="$3"
size="$5"
description="$6"
case "$1" in
need_mount)
2024-09-07 14:39:33 +02:00
do_need_mount "$work_dir" "$name" "$size" "$description"
2023-01-27 18:06:55 +01:00
;;
backup)
2024-09-07 14:39:33 +02:00
do_backup "$work_dir" "$name" "$size" "$description"
2023-01-27 18:06:55 +01:00
;;
mount)
2024-09-07 14:39:33 +02:00
do_mount "$work_dir" "$name" "$size" "$description"
2023-01-27 18:06:55 +01:00
;;
*)
echo "hook called with unknown argument \`$1'" >&2
exit 1
;;
esac
exit 0
```
Fichier de configuration des sauvegardes locales
**/etc/yunohost/hooks.d/backup_method/05-borg__2_app**
```
2024-09-07 14:39:33 +02:00
#!/usr/bin/env bash
set -Eeuo pipefail
2023-01-27 18:06:55 +01:00
2024-09-07 14:39:33 +02:00
borg="/var/www/borg__2/venv/bin/borg"
app="borg__2"
BORG_PASSPHRASE="$(yunohost app setting "$app" passphrase)"
BORG_REPO="$(yunohost app setting "$app" repository)"
BORG_LOGGING_CONF="/var/www/borg__2/logging.conf"
2023-01-27 18:06:55 +01:00
if ssh-keygen -F "" >/dev/null ; then
BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=yes "
else
BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=no "
fi
do_need_mount() {
true
}
do_backup() {
export BORG_PASSPHRASE
2024-09-07 14:39:33 +02:00
export BORG_REPO
2023-01-27 18:06:55 +01:00
export BORG_RSH
2024-09-07 14:39:33 +02:00
export BORG_LOGGING_CONF
2023-01-27 18:06:55 +01:00
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
work_dir="$1"
name="$2"
2024-09-07 14:39:33 +02:00
size="$3"
description="$4"
2023-01-27 18:06:55 +01:00
set +e
2024-09-07 14:39:33 +02:00
if ! "$borg" list > /dev/null 2>&1; then
"$borg" init -e repokey
# human_size=`echo $size | awk '{ suffix=" KMGT"; for(i=1; $1>1024 && i < length(suffix); i++) $1/=1024; print int($1) substr(suffix, i, 1), $3; }'`
# Speed in Kbps
# speed=1000
# evaluated_time=$(($size / ($speed * 1000 / 8) / 3600))
echo "Hello,
2023-01-27 18:06:55 +01:00
2024-09-07 14:39:33 +02:00
Your first backup on $BORG_REPO is starting.
2023-01-27 18:06:55 +01:00
This is an automated message from your beloved YunoHost server." | /usr/bin/mail.mailutils -a "Content-Type: text/plain; charset=UTF-8" -s "[YNH] First backup is starting" "root"
fi
set -e
2024-09-07 14:39:33 +02:00
# About the {now} placeholder:
# https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
# In the archive name, you may use the following placeholders: {now}, {utcnow}, {fqdn}, {hostname}, {user} and some others.
"$borg" create --stats "::${name}-{now}" "$work_dir"
"$borg" prune --glob-archives "${name}-*" --list --keep-hourly 2 --keep-daily=7 --keep-weekly=8 --keep-monthly=12
2023-01-27 18:06:55 +01:00
# We prune potential manual backup older than 1 year
2024-09-07 14:39:33 +02:00
"$borg" prune --list --keep-within 1y
2023-01-27 18:06:55 +01:00
}
do_mount() {
export BORG_PASSPHRASE
2024-09-07 14:39:33 +02:00
export BORG_REPO
2023-01-27 18:06:55 +01:00
export BORG_RSH
2024-09-07 14:39:33 +02:00
export BORG_LOGGING_CONF
2023-01-27 18:06:55 +01:00
work_dir="$1"
name="$2"
2024-09-07 14:39:33 +02:00
size="$3"
description="$4"
"$borg" mount "::$name" "$work_dir"
2023-01-27 18:06:55 +01:00
}
work_dir="$2"
name="$3"
size="$5"
description="$6"
case "$1" in
need_mount)
2024-09-07 14:39:33 +02:00
do_need_mount "$work_dir" "$name" "$size" "$description"
2023-01-27 18:06:55 +01:00
;;
backup)
2024-09-07 14:39:33 +02:00
do_backup "$work_dir" "$name" "$size" "$description"
2023-01-27 18:06:55 +01:00
;;
mount)
2024-09-07 14:39:33 +02:00
do_mount "$work_dir" "$name" "$size" "$description"
2023-01-27 18:06:55 +01:00
;;
*)
echo "hook called with unknown argument \`$1'" >&2
exit 1
;;
esac
exit 0
```