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

rustic snapshot json output #1362

Open
pierreedbrg opened this issue Nov 22, 2024 · 2 comments · May be fixed by #1375
Open

rustic snapshot json output #1362

pierreedbrg opened this issue Nov 22, 2024 · 2 comments · May be fixed by #1375
Labels
A-commands Area: Related to commands in `rustic` C-enhancement Category: New feature or request

Comments

@pierreedbrg
Copy link

  • is there a reason why the command rustic snapshots --json output is different from the from restic ?
    whould it be possible to align rustic output to the restic one ?

The reason if for retro compatibilty between scripts.

To get first snapshot id from the output, it was id="$(echo "$json" | jq -r '.[0].id')", now it is something like id="$(echo "$json" | jq -r '.[0][1][0].id')", and it can be even more nested if you add or remove filters in rustic snapshots command

[
    [
        {
            "hostname": "backup-container",
            "label": "",
            "paths": [
                "."
            ]
        },
        [
            {
                "time": "2024-11-22T10:31:42.716283767Z",
                "program_version": "rustic v0.9.4",
                "parent": "a0a853a8d9cd6e49c71274a59f1b2e960eb1c3fe3885a083f9e96019dc9db950",
                "tree": "6ed7153b87597e10714cc56f09275fae119837fbff77e918822e78f4e98e6ea3",
                "paths": [
                    "."
                ],
                "hostname": "backup-container",
                "username": "",
                "uid": 0,
                "gid": 0,
                "tags": [
                    "backupName:backup-sample-20240111171700",
                    "ttl:10s"
                ],
                "original": "7c4e274d6586dc520c07f10db456515c8fecad7fe3e86fcca3704954309d13fa",
                "summary": {
                    "files_new": 0,
                    "files_changed": 0,
                    "files_unmodified": 2,
                    "total_files_processed": 2,
                    "total_bytes_processed": 1924,
                    "dirs_new": 0,
                    "dirs_changed": 0,
                    "dirs_unmodified": 2,
                    "total_dirs_processed": 2,
                    "total_dirsize_processed": 1006,
                    "data_blobs": 0,
                    "tree_blobs": 0,
                    "data_added": 0,
                    "data_added_packed": 0,
                    "data_added_files": 0,
                    "data_added_files_packed": 0,
                    "data_added_trees": 0,
                    "data_added_trees_packed": 0,
                    "command": "rustic backup . --no-scan --custom-ignorefile /etc/rustic/.backupignore --host backup-container --tag=backupName:backup-sample-20240111171700 --tag=ttl:10s",
                    "backup_start": "2024-11-22T10:31:42.721161976Z",
                    "backup_end": "2024-11-22T10:31:42.724052641Z",
                    "backup_duration": 0.002890665,
                    "total_duration": 0.007768874
                },
                "id": "7c4e274d6586dc520c07f10db456515c8fecad7fe3e86fcca3704954309d13fa"
            },
            {
                "time": "2024-11-21T15:14:29.943246591Z",
                "program_version": "rustic v0.9.4",
                "tree": "6ed7153b87597e10714cc56f09275fae119837fbff77e918822e78f4e98e6ea3",
                "paths": [
                    "."
                ],
                "hostname": "backup-container",
                "username": "",
                "uid": 0,
                "gid": 0,
                "tags": [
                    "backupName:backup-sample-20240111171700",
                    "ttl:10s"
                ],
                "original": "a0a853a8d9cd6e49c71274a59f1b2e960eb1c3fe3885a083f9e96019dc9db950",
                "summary": {
                    "files_new": 2,
                    "files_changed": 0,
                    "files_unmodified": 0,
                    "total_files_processed": 2,
                    "total_bytes_processed": 1924,
                    "dirs_new": 2,
                    "dirs_changed": 0,
                    "dirs_unmodified": 0,
                    "total_dirs_processed": 2,
                    "total_dirsize_processed": 1006,
                    "data_blobs": 0,
                    "tree_blobs": 2,
                    "data_added": 1006,
                    "data_added_packed": 601,
                    "data_added_files": 0,
                    "data_added_files_packed": 0,
                    "data_added_trees": 1006,
                    "data_added_trees_packed": 601,
                    "command": "restic backup . --no-scan --custom-ignorefile /etc/rustic/.backupignore --host backup-container --tag=backupName:backup-sample-20240111171700 --tag=ttl:10s",
                    "backup_start": "2024-11-21T15:14:29.944300322Z",
                    "backup_end": "2024-11-21T15:14:29.967854226Z",
                    "backup_duration": 0.023553904,
                    "total_duration": 0.024607635
                },
                "id": "a0a853a8d9cd6e49c71274a59f1b2e960eb1c3fe3885a083f9e96019dc9db950"
            }
        ]
    ]
]

while restic snapshots --json outputs

[
    {
        "time": "2024-11-21T15:14:29.943246591Z",
        "tree": "6ed7153b87597e10714cc56f09275fae119837fbff77e918822e78f4e98e6ea3",
        "paths": [
            "."
        ],
        "hostname": "backup-container",
        "tags": [
            "backupName:backup-sample-20240111171700",
            "ttl:10s"
        ],
        "program_version": "rustic v0.9.4",
        "summary": {
            "backup_start": "2024-11-21T15:14:29.944300322Z",
            "backup_end": "2024-11-21T15:14:29.967854226Z",
            "files_new": 2,
            "files_changed": 0,
            "files_unmodified": 0,
            "dirs_new": 2,
            "dirs_changed": 0,
            "dirs_unmodified": 0,
            "data_blobs": 0,
            "tree_blobs": 2,
            "data_added": 1006,
            "data_added_packed": 601,
            "total_files_processed": 2,
            "total_bytes_processed": 1924
        },
        "id": "a0a853a8d9cd6e49c71274a59f1b2e960eb1c3fe3885a083f9e96019dc9db950",
        "short_id": "a0a853a8"
    },
    {
        "time": "2024-11-22T10:31:42.716283767Z",
        "parent": "a0a853a8d9cd6e49c71274a59f1b2e960eb1c3fe3885a083f9e96019dc9db950",
        "tree": "6ed7153b87597e10714cc56f09275fae119837fbff77e918822e78f4e98e6ea3",
        "paths": [
            "."
        ],
        "hostname": "backup-container",
        "tags": [
            "backupName:backup-sample-20240111171700",
            "ttl:10s"
        ],
        "program_version": "rustic v0.9.4",
        "summary": {
            "backup_start": "2024-11-22T10:31:42.721161976Z",
            "backup_end": "2024-11-22T10:31:42.724052641Z",
            "files_new": 0,
            "files_changed": 0,
            "files_unmodified": 2,
            "dirs_new": 0,
            "dirs_changed": 0,
            "dirs_unmodified": 2,
            "data_blobs": 0,
            "tree_blobs": 0,
            "data_added": 0,
            "data_added_packed": 0,
            "total_files_processed": 2,
            "total_bytes_processed": 1924
        },
        "id": "7c4e274d6586dc520c07f10db456515c8fecad7fe3e86fcca3704954309d13fa",
        "short_id": "7c4e274d"
    }
]
@github-actions github-actions bot added the S-triage Status: Waiting for a maintainer to triage this issue/PR label Nov 22, 2024
@aawsome
Copy link
Member

aawsome commented Nov 22, 2024

The reason is that rustic snapshots currently only offers grouped snapshots. The output of restic snapshots -g ... is like rustic's output.

I actually don't know why there is a double array [ [ instead of a single array - I would claim this as a bug.

@aawsome aawsome added C-bug Category: Something isn't working as expected A-commands Area: Related to commands in `rustic` C-enhancement Category: New feature or request and removed S-triage Status: Waiting for a maintainer to triage this issue/PR C-bug Category: Something isn't working as expected labels Dec 2, 2024
@aawsome
Copy link
Member

aawsome commented Dec 2, 2024

Ok, here is the reason for [ [:

  • we have an array of groups [
  • each groups consists of two entries: The group itself and the array of snapshots. These two entries are unnamed and hence given in an array [.
  • the group itself has named attributes and is given in {..}.
  • The array of snapshots is given as expected in [.

This also explains the 3 closing brackets ] ] ] at the end.

I propose to implement 2 enhancements for snapshots --json:

  • make named entries of group/snapshots. As names I propose (stolen from restic): "group_key" / "snapshots".
  • Don't show groups in the json when no grouping is requested, i.e. for the -g "" case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-commands Area: Related to commands in `rustic` C-enhancement Category: New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants