# Modifier la rétention des sauvegardes Borg

**URL:** https://forum.yunohost.org/t/modifier-la-retention-des-sauvegardes-borg/40889
**Category:** Support apps
**Tags:** borg, french, english
**Created:** [November 19, 2025, 12:56pm UTC](https://forum.yunohost.org/t/modifier-la-retention-des-sauvegardes-borg/40889 "2025-11-19T12:56:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Maiphyl](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/m/c68b51/32.png) [@Maiphyl](https://forum.yunohost.org/u/Maiphyl)
#### Post date: [November 19, 2025, 12:56pm UTC](https://forum.yunohost.org/t/modifier-la-retention-des-sauvegardes-borg/40889/1 "2025-11-19T12:56:35Z")

</div>

**What app is this about, and its version** : Borg 1.4.2~ynh1  
**What YunoHost version are you running** : 12.1.35  
**What type of hardware are you using** : Virtual machine

### Describe your issue

Hello,  
I searched (probably poorly) but couldn’t find how to change the retention of backups made with Borg.  
Could someone help me please?

Bonjour,  
j’ai cherché (sûrement mal) mais je n’ai pas trouvé comment modifier la rétention des sauvegardes faites avec Borg.  
Quelqu’un pourrait m’aider svp ?

### Share relevant logs or error messages

> **[hastebin](https://paste.yunohost.org/epebafasej)**

---

<div class="post-metadata">

### Author: ![ghose](https://forum.yunohost.org/user_avatar/forum.yunohost.org/ghose/32/10939_2.png) [@ghose](https://forum.yunohost.org/u/ghose)
#### Post date: [November 19, 2025, 1:45pm UTC](https://forum.yunohost.org/t/modifier-la-retention-des-sauvegardes-borg/40889/2 "2025-11-19T13:45:53Z")

</div>

in this file:

`/etc/yunohost/hooks.d/backup_method/05-borg_app`

edit this line:

`"$borg" prune --glob-archives "${name}-*" --keep-hourly 2 --keep-daily=7 --keep-weekly=8 --keep-monthly=12`

When YNH upgrades borg app this file is copied to `05-borg_app.backup` **AND** changed to default values.

Reference: [borg prune — Borg - Deduplicating Archiver 1.4.2.post1 documentation](https://borgbackup.readthedocs.io/en/stable/usage/prune.html)

---

<div class="post-metadata">

### Author: ![Maiphyl](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/m/c68b51/32.png) [@Maiphyl](https://forum.yunohost.org/u/Maiphyl)
#### Post date: [November 19, 2025, 2:30pm UTC](https://forum.yunohost.org/t/modifier-la-retention-des-sauvegardes-borg/40889/3 "2025-11-19T14:30:48Z")

</div>

Ok thanks.  
To check if it works, then run a manual backup or wait the next auto backup ?

---

<div class="post-metadata">

### Author: ![Nicouax](https://forum.yunohost.org/user_avatar/forum.yunohost.org/nicouax/32/12972_2.png) [@Nicouax](https://forum.yunohost.org/u/Nicouax)
#### Post date: [November 23, 2025, 2:44pm UTC](https://forum.yunohost.org/t/modifier-la-retention-des-sauvegardes-borg/40889/4 "2025-11-23T14:44:58Z")

</div>

Hi @Maiphyl,  
I recently set up backups with Borg and asked myself the very same question.

When using the Borg app, backups are triggered by the YunoHost hook mechanism and more specifically by the `backup_method` hook executed during the `yunohost backup create` command. For more informations about YunoHost hooks, see this page: [Hooks | Yunohost](https://doc.yunohost.org/en/dev/packaging/advanced/hooks/)

As @ghose pointed out, editing the `prune` command in the `/etc/yunohost/hooks.d/backup_method/05-borg_app` file allows you to customize the default backup retention values, but these changes will be overwritten with every Borg app update. For a slightly more robust solution, you can implement your own script that would run right after `05-borg_app` in order to tighten Borg retention policy. Your custom script won’t be removed when the Borg app is updated.

**Create the file that will contain your custom script:**

```auto
sudo micro /etc/yunohost/hooks.d/backup_method/06-borg_app_overlay

```

_I use Micro but any text editor will do (Nano is installed by default on all Debian distributions, I believe). You can name your file whatever you like but the “06-” prefix is important because it will make your script run after `05-borg_app`._

**This file must contain:**

```auto
#!/usr/bin/env bash
# Custom backup_method hook overlay that tighten Borg retention policy

# Enforce pipe error management
set -Eeuo pipefail

# Set path to Borg binary
borg="/var/www/borg/venv/bin/borg"

# Load Borg app environment
if [[-f /var/www/borg/.env]]; then
    set -a
    source /var/www/borg/.env
    set +a
fi

# Ensure Borg uses the same logging configuration as the main hook
export BORG_LOGGING_CONF='/var/www/borg/logging.conf'

# Set variables related to backup_method hook arguments
action="$1"
name="$3"

# Set retention variables
KEEP_DAILY=7
KEEP_WEEKLY=2
KEEP_MONTHLY=1

case "$action" in
    need_mount)
        # Do nothing
        true
        ;;
    backup)
        echo "Overlay hook - Tightening retention policy for ${name}-*"
        "$borg" prune --list --glob-archives "${name}-*" \
            --keep-daily="${KEEP_DAILY}" \
            --keep-weekly="${KEEP_WEEKLY}" \
            --keep-monthly="${KEEP_MONTHLY}"
        ;;
    mount)
        # Do nothing
        true
        ;;
  *)
    echo "Overlay hook - Unknown action: '$action'" >&2
    exit 1
    ;;
esac

exit 0

```

_You can edit the `KEEP_DAILY`, `KEEP_WEEKLY` and `KEEP_MONTHLY` variables to your liking._

**You can then restrict file permissions (the script only needs to be readable by root):**

```auto
sudo chmod 400 /etc/yunohost/hooks.d/backup_method/06-borg_app_overlay

```

To check if this works, I have not yet found a better way than waiting for the next scheduled backup (running `yunohost backup create` would also create local backups for all your apps, and running `systemctl start borg` wouldn’t go through YunoHost hook mechanism).

Keep in mind that after implementing your custom script, Borg will try to prune each repo twice per backup. This introduces a slight overhead and means this solution is only suitable if you want to keep fewer backups than what the Borg app offers by default (because your custom script will run after the `05-borg_app` script has already removed some backups according to the default settings).

As I just came up with this solution, I would be glad to hear any ideas that could improve it or any alternative to modify Borg backup retention 🙂

---

<div class="post-metadata">

### Author: ![Maiphyl](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/m/c68b51/32.png) [@Maiphyl](https://forum.yunohost.org/u/Maiphyl)
#### Post date: [November 26, 2025, 11:18am UTC](https://forum.yunohost.org/t/modifier-la-retention-des-sauvegardes-borg/40889/5 "2025-11-26T11:18:05Z")

</div>

Hi @Nicouax !

First, THANK YOU ! Your reply is very awesome 🙂

I’m trying your solution and i will come back to give my feedback.

---

<div class="post-metadata">

### Author: ![system](https://forum.yunohost.org/uploads/default/original/2X/f/f59fe8e3ee6b100b4f574d30d6e30479c68b89f0.png) [@system](https://forum.yunohost.org/u/system)
#### Post date: [December 11, 2025, 11:18am UTC](https://forum.yunohost.org/t/modifier-la-retention-des-sauvegardes-borg/40889/6 "2025-12-11T11:18:13Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
