Boîte de stockage distante bx11-yann-02

Boîte de stockage distante bx11-yann-02

Notes

Boîte stockage bx11-yann-02

Borg clés ssh pc1

En mode su

Créer une clé SSH pour l’authentification borg

1
ssh-keygen -t ed25519 -f /root/.ssh/id_borg-bx11-yann-02

Validez en appuyant sur la touche « Entrée » à toutes les questions

Vous devriez maintenant avoir une clé privée contenue dans le fichier /root/.ssh/id_borg-bx11-yann-02, et une clé publique contenue dans le fichier /root/.ssh/id_borg-bx11-yann-02.pub

La clé privée ne doit jamais être partagée.

Ajout clé publique borg pc1 à bx11-yann-02

Depuis un poste ayant accès à la boîte de stockage, on récupère le fichier authorized_keys dans un fichier nommé storagebox_authorized_keys

1
echo -e "get .ssh/authorized_keys storagebox_authorized_keys_02" | sftp -P 23 -i ~/.ssh/bx11-yann-02 u694796@u694796.your-storagebox.de

Copier/coller le contenu du fichier du fichier de clef publique (fichier cat /home/yann/.ssh/bx11-yann-02.pub* de la machine à sauvegarder dans ce terminal

1
cat >> storagebox_authorized_keys_02

et presser [Ctrl]+[D] pour valider.

On renvoie le fichier modifié storagebox_authorized_keys dans le fichier authorized_keys de la boîte de stockage bx11-yann

1
echo -e "put storagebox_authorized_keys_02 .ssh/authorized_keys" | sftp -P 23 -i ~/.ssh/bx11-yann-02 u694796@u694796.your-storagebox.de

Test connexion SFTP avec Clé

A-Root clé privée /root/.ssh/id_borg-bx11-yann-02
Tester la connexion depuis le vps à la boîte de stockage (toujours en mode su)

1
sftp -P 23 -i /root/.ssh/id_borg-bx11-yann-02 u694796@u694796.your-storagebox.de
1
2
3
4
5
6
7
The authenticity of host '[u326239.your-storagebox.de]:23 ([2a01:4f8:2b02:135::2]:23)' can't be established.
ED25519 key fingerprint is SHA256:XqONwb1S0zuj5A1CDxpOSuD2hnAArV1A3wKY7Z3sdgM.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[u326239.your-storagebox.de]:23' (ED25519) to the list of known hosts.
Connected to u326239.your-storagebox.de.
sftp> 

Saisir quit pour sortir

B-Utilisateur clé privée ~/.ssh/bx11-yann-02

1
sftp -P 23 -i ~/.ssh/bx11-yann-02 u694796@u694796.your-storagebox.de

Borg initialisation dépôt yann-crypto

  • Storage Box: bx11-yann-02
  • PassPhrase: dware -n 8 |tee $HOME/sharenfs/pc1/.borg/yann-crypto.passphrase
  • Exclusions: touch /home/yann/.borg/yann-crypto.exclusions (A remplir, une exclusion par ligne)
  • Dépôt cryptomator: ssh://u694796@u694796.your-storagebox.de:23/./yann-crypto

Initialisation dépôt yann-crypto

1
2
3
4
export BORG_PASSPHRASE="`cat /home/yann/.borg/yann-crypto.passphrase`"
export BORG_RSH='ssh -i /home/yann/.ssh/bx11-yann-02'
BORG_REPOSITORY='ssh://u694796@u694796.your-storagebox.de:23/./yann-crypto'
borg init --encryption=repokey-blake2 $BORG_REPOSITORY

Borg Script de sauvegarde

Script de sauvegarde borg-backup-yann-crypto.sh (notez l’usage de borg prune pour supprimer les archives trop anciennes)

1
sudo nano /home/yann/scripts/borg-backup-yann-crypto.sh

Le script /home/yann/scripts/borg-backup-yann-crypto.sh avec envoi message via ntfy

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
#!/bin/sh
#
# Script de sauvegarde.
#

. "$HOME/.ntfy_env"

t=$(date +%s)


export BORG_PASSPHRASE="$(cat /home/yann/.borg/yann-crypto.passphrase)"
export BORG_RSH='ssh -i /home/yann/.ssh/bx11-yann-02'
BORG_PATH="/home/yann/.coffre-cryptomator/yann-crypto"
BORG_EXCLUSION="/home/yann/.borg/yann-crypto.exclusions"
BORG_REPOSITORY=ssh://u694796@u694796.your-storagebox.de:23/./yann-crypto

BACKUP_DATE=`date +%Y-%m-%d-%Hh%M`
INFO="Coffre chiffré yann-crypto"

CMD_CREATE="borg create -v --progress --stats --exclude-from $BORG_EXCLUSION \"${BORG_REPOSITORY}::${BACKUP_DATE}\" $BORG_PATH"
borg create -v --progress --stats --exclude-from $BORG_EXCLUSION "${BORG_REPOSITORY}::${BACKUP_DATE}" $BORG_PATH
rc_create=$?

CMD_PRUNE="borg prune -v --stats --keep-daily=7 --keep-weekly=1 --keep-monthly=1 \"${BORG_REPOSITORY}\""
borg prune -v --stats --keep-daily=7 --keep-weekly=1 --keep-monthly=1 "$BORG_REPOSITORY"
rc_prune=$?

d=$(( $(date +%s) - t ))
DUREE=$(( d / 3600 ))h$(( (d % 3600) / 60 ))m$(( d % 60 ))s

s_create="❌"
[ $rc_create -eq 0 ] && s_create="✔️"

s_prune="❌"
[ $rc_prune -eq 0 ] && s_prune="✔️"

msg_title="🔐 $INFO : Borgbackup en $DUREE"

{
  echo
  echo "${s_create} ${CMD_CREATE}"
  echo
  echo "${s_prune} ${CMD_PRUNE}"
} | curl -sS -X POST \
  -H "X-Email: $NTFY_EMAIL" \
  -H "Title: $msg_title" \
  -H "Authorization: Bearer $NTFY_TOKEN" \
  -H "prio:low" \
  -H "Content-Type: text/plain; charset=utf-8" \
  --data-binary @- \
  "$NTFY_URL"

Le rendre exécutable

1
sudo chmod +x /home/yann/scripts/borg-backup-yann-crypto.sh

Environnement ntfy $HOME/.ntfy_env

1
2
3
NTFY_URL=https://ntfy.rnmkcy.eu/yan_infos
NTFY_TOKEN=tk_xxxxxxxxxxxxxxxxxxx
NTFY_EMAIL=ntfy@domain.tld

Modifier la valeur Bearer tk_... et le domaine domain.tld

Automatiser sauvegarde BorgBackup

Automatiser en utilisant systemd timer
Le service /etc/systemd/system/autoborg.service

1
2
3
4
5
6
7
8
9
[Unit]
Description=BorgBackup

[Service]
User=root
ExecStart=/usr/bin/bash /home/yann/scripts/borg-backup-yann-crypto.sh

[Install]
WantedBy=multi-user.target

Le timer /etc/systemd/system/autoborg.timer

1
2
3
4
5
6
7
8
9
[Unit]
Description=Exécution BorgBackup

[Timer]
Unit=autoborg.service
OnCalendar=*-*-* 03:15

[Install]
WantedBy=timers.target

Exécution tous les jours

Activez/démarrez le timer, puis vérifiez qu’il est chargé et actif

1
2
3
sudo systemctl daemon-reload
sudo systemctl enable autoborg.timer --now
systemctl status autoborg.timer

Vérifiez s’il apparaît dans la liste des minuteries :

1
systemctl list-timers --no-pager
1
2
NEXT                    LEFT LAST                      PASSED UNIT                ACTIVATES           
Wed 2026-04-22 03:…      17h -                              - autoborg.timer      autoborg.service

Lorsque vous voulez voir si les sauvegardes se sont déroulées correctement, vous pouvez consulter le journal le plus récent

1
systemctl status autoborg

Ou afficher tous les journaux avec :

1
sudo journalctl -u autoborg

Pour lancer une sauvegarde manuellement

1
/usr/bin/bash /home/yann/scripts/borg-backup-yann-crypto.sh

Liste des sauvegardes

Pour lister les sauvegardes

1
2
3
4
5
# en mode su
export BORG_PASSPHRASE="$(cat /home/yann/.borg/yann-crypto.passphrase)"
export BORG_RSH='ssh -i /home/yann/.ssh/bx11-yann-02'
BORG_REPOSITORY=ssh://u694796@u694796.your-storagebox.de:23/./yann-crypto
borg list --short  $BORG_REPOSITORY

Donne un résultat de ce type

1
2026-04-21-10h03

Tags tendance