Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidePrincipi committed Oct 31, 2024
1 parent b7b2de9 commit 20ff8ae
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions imageroot/actions/list-backup-contents/50list_backup_contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3

#
# Copyright (C) 2024 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import json
import sys
import os
import subprocess

request = json.load(sys.stdin)


backup_id = request['backup']
folders = []

restic_cmd = ["restic-wrapper", "--backup=" + str(backup_id), "dump", request["snapshot"], "/state/maildir-dump.lst"]

with subprocess.Popen(restic_cmd, stdout=subprocess.PIPE, stderr=sys.stderr, text=True) as vproc:

while True:
line = vproc.stdout.readline()
if not line:
break
fields = line.rstrip().split("\t")
if fields[0] == request["user"]:
folders.append(fields[1])

folders.sort()

json.dump({
"backup": request['backup'],
"snapshot": request['snapshot'],
"user": request['user'],
"folders": folders,
}, fp=sys.stdout)

0 comments on commit 20ff8ae

Please sign in to comment.