This commit is contained in:
Vladyslav Yurchenko
2026-01-15 15:11:42 +02:00
parent 440e65d310
commit 022ba5fcfa
4 changed files with 19 additions and 17 deletions

View File

@@ -54,7 +54,7 @@ type individualFile struct {
resourceName string
containerName string
filepaths []string
dirpaths []string
dirpaths map[string][]string
}
// resourceMap struct is used to dump the resources from namespace scope or cluster scope

View File

@@ -22,20 +22,22 @@ func (d *Dumper) getIndividualFiles(ctx context.Context, job exportJob, crType s
log.Printf("Skipping file %q. Failed to parse ENV's", indPath)
continue
}
if err := d.processSingleFile(ctx, job, indf.containerName, indPath); err != nil {
if err := d.processSingleFile(ctx, job, indf.containerName, "", indPath); err != nil {
log.Printf("Skipping file %q: %v", indPath, err)
}
}
for _, dirPath := range indf.dirpaths {
dirPath, err = d.ParseEnvsFromSpec(ctx, job.Pod.Namespace, job.Pod.Name, indf.containerName, dirPath)
if err != nil {
log.Printf("Skipping directory %q. Failed to parse ENV's", dirPath)
continue
}
for tarFolder, dirPaths := range indf.dirpaths {
for _, dirPath := range dirPaths {
dirPath, err = d.ParseEnvsFromSpec(ctx, job.Pod.Namespace, job.Pod.Name, indf.containerName, dirPath)
if err != nil {
log.Printf("Skipping directory %q. Failed to parse ENV's", dirPath)
continue
}
if err := d.processDir(ctx, job, indf.containerName, dirPath); err != nil {
log.Printf("Skipping directory %q: %v", dirPath, err)
if err := d.processDir(ctx, job, indf.containerName, tarFolder, dirPath); err != nil {
log.Printf("Skipping directory %q: %v", dirPath, err)
}
}
}
}
@@ -44,7 +46,7 @@ func (d *Dumper) getIndividualFiles(ctx context.Context, job exportJob, crType s
func (d *Dumper) processSingleFile(
ctx context.Context,
job exportJob,
container, filePath string,
container, tarFolder, filePath string,
) error {
tr, rc, stderr, err := d.tarFromPod(ctx, job.Pod, container, filePath)
@@ -73,7 +75,7 @@ func (d *Dumper) processSingleFile(
dst := d.PodIndividualFilesPath(
job.Pod.Namespace,
job.Pod.Name,
path.Base(filePath),
path.Join(tarFolder, path.Base(filePath)),
)
return d.archive.WriteFile(dst, tr, hdr.Size)
@@ -85,7 +87,7 @@ func (d *Dumper) processSingleFile(
func (d *Dumper) processDir(
ctx context.Context,
job exportJob,
container, dir string,
container, tarFolder, dir string,
) error {
tr, rc, _, err := d.tarFromPod(ctx, job.Pod, container, "-C", dir, ".")
@@ -110,7 +112,7 @@ func (d *Dumper) processDir(
dst := d.PodIndividualFilesPath(
job.Pod.Namespace,
job.Pod.Name,
path.Base(hdr.Name),
path.Join(tarFolder, path.Base(hdr.Name)),
)
if err := d.archive.WriteFile(dst, tr, hdr.Size); err != nil {

View File

@@ -11,8 +11,8 @@ import (
var resourcesRe = regexp.MustCompile(`(\w+\.(\w+).percona\.com)`)
func (d *Dumper) addPg1() error {
dirpaths := []string{
"$PGBACKREST_DB_PATH/pg_log",
dirpaths := map[string][]string{
"pg_log": {"$PGBACKREST_DB_PATH/pg_log"},
}
d.individualFiles = append(d.individualFiles, individualFile{

View File

@@ -229,7 +229,7 @@ func TestIndividualFiles(t *testing.T) {
// if the tool collects required pg log files
name: "pg_logs_list",
resource: "pg",
cmd: []string{"tar", "-tf", "cluster-dump.tar.gz", "--wildcards", "cluster-dump/*/*/*"},
cmd: []string{"tar", "-tf", "cluster-dump.tar.gz", "--wildcards", "cluster-dump/*/*/pg_log/*"},
preprocessor: uniqueBasenames,
match: RegexMatch{
Pattern: regexp.MustCompile(`^postgresql-[A-Za-z]{3}\.log$`),