Borgbackup PC1
Borgbackup
BorgBackup (abrégé : Borg) est un programme de sauvegarde par déduplication. En option, il prend en charge la compression et le chiffrement authentifié. L’objectif principal de Borg est de fournir un moyen efficace et sûr de sauvegarder des données.
Sauvegardes
Fichier environnement ntfy $HOME/.config/ntfy.env (mode utilisateur)
1
2
3
4
5
6
7
# Environnement ntfy
echo "NTFY_URL="https://ntfy.rnmkcy.eu/yan_infos"
NTFY_TOKEN="tk_xxxxxxxxxxxxxxxxxxxxxxx"
NTFY_EMAIL="ntfy@cinay.eu"" | tee -a $HOME/.config/ntfy.env
# Protection
chown $USER:$USER $HOME/.config/ntfy.env
chmod 600 $HOME/.config/ntfy.env
Modifier la valeur NTFY_TOKEN...
BorgBackup home et media
Créer le dépôt
1
2
3
4
export BORG_PASSPHRASE="`cat /home/yann/sharenfs/pc1/.borg/pc1.passphrase`"
export BORG_RSH='ssh -i /root/.ssh/id_borg_ed25519'
BORG_REPOSITORY='/home/yann/FreeUSB2To/sauvegardes/borgbackup/pc1'
borg init --encryption=repokey-blake2 $BORG_REPOSITORY
BorgBackup est installé et fonctionnel en local
Script borg_pc1_media.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
#
# Environnement ntfy
. "$HOME/.config/ntfy.env"
# Modifié 03/08/2026
today="$(date +%F)" # Europe/Paris
state_file="$HOME/.pc1_last_run_date"
# Vérifier si state_file existe
if [[ ! -f "$state_file" ]]; then
# Créer un fichier vide
touch "$state_file"
fi
# Si sauvegarde jour effectuée -> on sort
# Sinon lancement sauvegarde
last="$(cat "$state_file" 2>/dev/null || true)"
if [[ "$last" == "$today" ]]; then
echo "Sauvegarde borg déjà réalisée"
curl \
-H "X-Email: $NTFY_EMAIL" \
-H "Title: ℹ️ BorgBackup PC1 déjà réalisée ce jour" \
-H "Authorization: Bearer $NTFY_TOKEN" \
-H prio:low \
-d "PC1 $0" \
"$NTFY_URL"
exit 0
else
echo "Départ sauvegarde borg"
# Départ sauvegarde borg
#
BORG_LINK_REPOSITORY="/home/yann/FreeUSB2To/sauvegardes/borgbackup"
#BORG_LINK_REPOSITORY= "ssh://u326239@u326239.your-storagebox.de:23/./backup/borg"
# Pour le calcul du temps d'exécution
t=$(date +%s)
echo "Exécution script $0"
echo "Borgbackup PC1 /home/yann/"
## PC1 /home/yann/ - Sauvegarde Borg
export BORG_PASSPHRASE="`cat /home/yann/sharenfs/pc1/.borg/pc1.passphrase`"
export BORG_RSH='ssh -i /home/yann/sharenfs/pc1/.borg/pc1.borgssh'
BORG_REPOSITORY="$BORG_LINK_REPOSITORY/pc1"
BACKUP_DATE=`date +%Y-%m-%d-%Hh%M`
borg create -v --progress --stats --exclude-from /home/yann/sharenfs/pc1/.borg/pc1.exclusions ${BORG_REPOSITORY}::${BACKUP_DATE} /home/yann/
borg prune -v --list --stats --keep-daily=7 --keep-weekly=4 --keep-monthly=6 $BORG_REPOSITORY
# Calcul et affichage temps exécution
d=$(($(date +%s) - $t))
DUREE=$(($d / 3600 ))h$((($d % 3600) / 60))m$(($d % 60))s
# Drapeau pour dire que la sauvegarde a été effectuée
echo "$today" > "$state_file"
echo "FIN sauvegarde borg"
# notification notify-send
#DISPLAY=:0 notify-send "$0" "Fin sauvegarde\n Durée : $temps_execution" -i /home/yann/media/statique/images/information.png -t 10000
# Message
# -H "X-Email: ntfy@cinay.eu" \
curl \
-H "X-Email: $NTFY_EMAIL" \
-H "Title: BorgBackup PC1 /home/yann/ en $DUREE" \
-H "Authorization: Bearer $NTFY_TOKEN" \
-H prio:low \
-d "PC1 $0
✔️ Fin Borgbackup /home/yann/ --> dépôt $BORG_REPOSITORY" \
"$NTFY_URL"
fi
exit 0
Pour exécuter une tâche une fois par jour, en suivant l’horloge (même si la machine a été arrêtée / redémarrée)
Le fichier service ~/.config/systemd/user/borg_pc1_media.service
1
2
3
4
5
6
[Unit]
Description=Sauvegarde jour
[Service]
Type=oneshot
ExecStart=/bin/bash /home/yann/scripts/borg_pc1_media.sh
Le fichier “timer” ~/.config/systemd/user/borg_pc1_media.timer
1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Exécution quotidienne sauvegarde
[Timer]
OnCalendar=daily
Persistent=true
# optionnel : éviter un démarrage pile à la seconde exacte
RandomizedDelaySec=5m
[Install]
WantedBy=timers.target
OnCalendar=daily: déclenche selon le calendrier (une exécution par jour).Persistent=true: si le système était arrêté au moment du déclenchement, systemd rattrape au prochain démarrage (exécute pour les échéances manquées).
Activation et lancement
1
2
systemctl --user daemon-reload
systemctl --user enable borg_pc1_media.timer --now
Les logs : journalctl --user -u savyann.service
Liste des timers :
1
systemctl --user list-timers --all
1
2
NEXT LEFT LAST PASSED UNIT ACTIVATES
Tue 2026-08-04 00:00:05 CEST 13h Mon 2026-08-03 06:02:03 CEST - borg_pc1_media.timer borg_pc1_media.service
BorgBackup home et media ➔ Box bx11-yann-02
Créer le dépôt
1
2
3
4
export BORG_PASSPHRASE="`cat /home/yann/sharenfs/pc1/.borg/pc1.passphrase`"
export BORG_RSH='ssh -i /root/.ssh/id_borg_ed25519'
BORG_REPOSITORY='/home/yann/FreeUSB2To/sauvegardes/borgbackup/pc1'
borg init --encryption=repokey-blake2 $BORG_REPOSITORY
BorgBackup est installé et fonctionnel en local
Script borg_pc1_media.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
#
# Environnement ntfy
. "$HOME/.config/ntfy.env"
# Modifié 03/08/2026
today="$(date +%F)" # Europe/Paris
state_file="$HOME/.pc1_last_run_date"
# Vérifier si state_file existe
if [[ ! -f "$state_file" ]]; then
# Créer un fichier vide
touch "$state_file"
fi
# Si sauvegarde jour effectuée -> on sort
# Sinon lancement sauvegarde
last="$(cat "$state_file" 2>/dev/null || true)"
if [[ "$last" == "$today" ]]; then
echo "Sauvegarde borg déjà réalisée"
curl \
-H "X-Email: $NTFY_EMAIL" \
-H "Title: ℹ️ BorgBackup PC1 déjà réalisée ce jour" \
-H "Authorization: Bearer $NTFY_TOKEN" \
-H prio:low \
-d "PC1 $0" \
"$NTFY_URL"
exit 0
else
echo "Départ sauvegarde borg"
# Départ sauvegarde borg
#
BORG_LINK_REPOSITORY="/home/yann/FreeUSB2To/sauvegardes/borgbackup"
#BORG_LINK_REPOSITORY= "ssh://u326239@u326239.your-storagebox.de:23/./backup/borg"
# Pour le calcul du temps d'exécution
t=$(date +%s)
echo "Exécution script $0"
echo "Borgbackup PC1 /home/yann/"
## PC1 /home/yann/ - Sauvegarde Borg
export BORG_PASSPHRASE="`cat /home/yann/sharenfs/pc1/.borg/pc1.passphrase`"
export BORG_RSH='ssh -i /home/yann/sharenfs/pc1/.borg/pc1.borgssh'
BORG_REPOSITORY="$BORG_LINK_REPOSITORY/pc1"
BACKUP_DATE=`date +%Y-%m-%d-%Hh%M`
borg create -v --progress --stats --exclude-from /home/yann/sharenfs/pc1/.borg/pc1.exclusions ${BORG_REPOSITORY}::${BACKUP_DATE} /home/yann/
borg prune -v --list --stats --keep-daily=7 --keep-weekly=4 --keep-monthly=6 $BORG_REPOSITORY
# Calcul et affichage temps exécution
d=$(($(date +%s) - $t))
DUREE=$(($d / 3600 ))h$((($d % 3600) / 60))m$(($d % 60))s
# Drapeau pour dire que la sauvegarde a été effectuée
echo "$today" > "$state_file"
echo "FIN sauvegarde borg"
# notification notify-send
#DISPLAY=:0 notify-send "$0" "Fin sauvegarde\n Durée : $temps_execution" -i /home/yann/media/statique/images/information.png -t 10000
# Message
# -H "X-Email: ntfy@cinay.eu" \
curl \
-H "X-Email: $NTFY_EMAIL" \
-H "Title: BorgBackup PC1 /home/yann/ en $DUREE" \
-H "Authorization: Bearer $NTFY_TOKEN" \
-H prio:low \
-d "PC1 $0
✔️ Fin Borgbackup /home/yann/ --> dépôt $BORG_REPOSITORY" \
"$NTFY_URL"
fi
exit 0
Pour exécuter une tâche une fois par jour, en suivant l’horloge (même si la machine a été arrêtée / redémarrée)
Le fichier service ~/.config/systemd/user/borg_pc1_media.service
1
2
3
4
5
6
[Unit]
Description=Sauvegarde jour
[Service]
Type=oneshot
ExecStart=/bin/bash /home/yann/scripts/borg_pc1_media.sh
Le fichier “timer” ~/.config/systemd/user/borg_pc1_media.timer
1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Exécution quotidienne sauvegarde
[Timer]
OnCalendar=daily
Persistent=true
# optionnel : éviter un démarrage pile à la seconde exacte
RandomizedDelaySec=5m
[Install]
WantedBy=timers.target
OnCalendar=daily: déclenche selon le calendrier (une exécution par jour).Persistent=true: si le système était arrêté au moment du déclenchement, systemd rattrape au prochain démarrage (exécute pour les échéances manquées).
Activation et lancement
1
2
systemctl --user daemon-reload
systemctl --user enable borg_pc1_media.timer --now
Les logs : journalctl --user -u savyann.service
Liste des timers :
1
systemctl --user list-timers --all
1
2
NEXT LEFT LAST PASSED UNIT ACTIVATES
Tue 2026-08-04 00:00:05 CEST 13h Mon 2026-08-03 06:02:03 CEST - borg_pc1_media.timer borg_pc1_media.service
Restauration
Créer un dossier pour restaurer les éléments sauvegardés par borgbackup
1
mkdir $HOME/borgbackup
Modifier le script $HOME/scripts/borglistnew.sh
1
2
# Dossier de montage pour borg mount et extract (par défaut)
export BORGLOC=$HOME/borgbackup
Créer un alias pour lancer le script $HOME/scripts/borglistnew.sh
1
nano ~/.bash_aliases
Ajouter la ligne suivante
1
alias borglist='cd $HOME/borgbackup/; $HOME/scripts/borglistnew.sh'
Recharger
1
source ~/.bashrc