Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring a retention on a stdin profile applies the retention policy to the whole repository #225

Closed
Lucki opened this issue Jun 10, 2023 · 3 comments

Comments

@Lucki
Copy link

Lucki commented Jun 10, 2023

I'm new to restic and maybe I'm interpreting the command output wrong.
I have a few profiles in the configuration. Some normal path profiles and a stdin profile. One profile has no retention configured.

The retention output for the normal profile looked correct, listing all snapshots of that profile only and declaring the reasons to keep each one.
However, the output of the forget command from a stdin profile got me thinking:
[…] keep 2 snapshots: […] Reasons: daily within 7d […] is listed for a third profile, although that specific profile has no retention. In fact that command listed all profiles with the same retention policy.

The difference seems to be the --path=… command line flag which is missing for the profile using stdin.

Retention command after normal profile:

starting command: /usr/bin/restic forget […] --path=/home/lucki --prune --repo=local:/run/media/lucki/backup/restic --verbose=1

Retention command after stdin profile which applies to all profiles including a profile without retention:

starting command: /usr/bin/restic forget […] --prune --repo=local:/run/media/lucki/backup/restic --verbose=1

My uneducated guess is that the absence of the --path= flag will apply the retention policy to the whole repository regardless of other configured retention policies.

Reference example: https://creativeprojects.github.io/resticprofile/configuration/examples/index.html#use-stdin-in-configuration

My trimmed config
version = "1"

[default]
    repository = "local:/run/media/lucki/backup/restic"
    verbose = true

[home]
    inherit = "default"

    [home.backup]
        source = [
            "/home/lucki",
        ]

    [home.retention]
        before-backup = false
        after-backup = true
        keep-within-yearly = "5y"
        keep-within-monthly = "1y"
        keep-within-weekly = "1m"
        keep-within-daily = "7d"
        prune = true

[gitea]
    inherit = "default"

    [gitea.backup]
        stdin-filename = "gitea.sql"
        stdin-command = [
            "pg_dump …",
        ]

    [gitea.retention]
        before-backup = false
        after-backup = true
        keep-within-yearly = "5y"
        keep-within-monthly = "1y"
        keep-within-weekly = "1m"
        keep-within-daily = "7d"
        prune = true

[third]
    inherit = "default"

    [third.backup]
        source = [
            "/mnt/third",
        ]

        # Notice *no* retention!

Bonus question:
While for includes it is made very clear that they can't nest this isn't specifically mentioned for inherited profiles. Is nesting possible for inherited profiles?

@jkellerer
Copy link
Collaborator

Retention automatically applies a --path filter (taken from backup source) to match only those snapshots in the repo that point to this path.

When using "stdin-filename" instead of a backup source, there is no --path to apply and "retention" (restic forget) will match any snapshot in the repository.

Try using:

[gitea]
    inherit = "default"

    [gitea.backup]
        stdin-filename = "gitea.sql"
        stdin-command = [
            "pg_dump …",
        ]
        tag = ["gitea", "pg_dump"]

    [gitea.retention]
        tag = true
        after-backup = true
        keep-within-yearly = "5y"
        keep-within-monthly = "1y"
        keep-within-weekly = "1m"
        keep-within-daily = "7d"
        prune = true

retention supports tag=true (implicit in version=2), path=true (implicit in version=1 & 2) and host=true to reuse --path, --tag and --host from backup.

To the bonus question: Inheritance can be nested it is not limited explicitly.

@Lucki
Copy link
Author

Lucki commented Jun 13, 2023

Thanks for all your answers, I must have overlooked the tag option or missed the connection to stdin.
May I suggest documenting a short note near the stdin profile example?

E.g. as a quick thought:
[mysql]
  inherit = "stdin"

  [mysql.backup]
    stdin-command = [ 'mysqldump --all-databases --order-by-primary' ]
    stdin-filename = "dump.sql"
    tag = [ 'mysql' ]

    # To limit stdin profile retention policies use the tag=true option

From my first observation limiting the retention to tags is not "additive", the retention in your example will affect all snapshots having the tag gitea and all snapshots having the tag pg_dump.

@Lucki Lucki closed this as completed Jun 13, 2023
@jkellerer
Copy link
Collaborator

@Lucki: "tags not additive" ... yes that is a bug, I realised myself after writing a reply to this case. See #227 (second commit will fix this). As a workaround, use a singe tag at the moment. The problem is that the tag parameter is not the same for backup and other restic commands. Therefore the copy function (tag=true) must address this.

The need for documentation on retention is noted. It will also include an update for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants