Skip to content

Commit a2606e1

Browse files
committed
Merge branch '277-logical-plain-text-restore' into 'master'
feat: support restoring from a plain-text files (#277) Closes #277 See merge request postgres-ai/database-lab!311
2 parents 3a17b68 + 968f5cb commit a2606e1

File tree

5 files changed

+379
-39
lines changed

5 files changed

+379
-39
lines changed

configs/config.example.logical_generic.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ retrieval:
148148
options:
149149
# The dump file will be automatically created on this location and then used to restore.
150150
# Ensure that there is enough disk space.
151-
dumpLocation: "/var/lib/dblab/dblab_pool/dump/db.dump"
151+
dumpLocation: "/var/lib/dblab/dblab_pool/dump"
152152

153153
# The Docker image containing the tools required to get a dump.
154154
dockerImage: "postgresai/extended-postgres:13"
@@ -179,7 +179,7 @@ retrieval:
179179
# database1:
180180
# # Option for a partial dump. Do not specify the tables section to dump all available tables.
181181
# tables:
182-
# - test
182+
# - table1
183183
# database2:
184184
# databaseN:
185185

@@ -207,8 +207,8 @@ retrieval:
207207
# "restore" option in the "logicalDump" job.
208208
logicalRestore:
209209
options:
210-
# The location of the archive file (or directory, for a directory-format archive) to be restored.
211-
dumpLocation: "/var/lib/dblab/dblab_pool/dump/db.dump"
210+
# The location of the archive files (or directories, for directory-format archives) to be restored.
211+
dumpLocation: "/var/lib/dblab/dblab_pool/dump"
212212

213213
# The Docker image containing the tools required to restore.
214214
dockerImage: "postgresai/extended-postgres:13"

configs/config.example.logical_rds_iam.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ retrieval:
147147
options:
148148
# The dump file will be automatically created on this location and then used to restore.
149149
# Ensure that there is enough disk space.
150-
dumpLocation: "/var/lib/dblab/dblab_pool/dump/rds_db.dump"
150+
dumpLocation: "/var/lib/dblab/dblab_pool/dump"
151151

152152
# The Docker image containing the tools required to get a dump.
153153
dockerImage: "postgresai/extended-postgres:13"
@@ -210,7 +210,7 @@ retrieval:
210210
logicalRestore:
211211
options:
212212
# The location of the archive file (or directory, for a directory-format archive) to be restored.
213-
dumpLocation: "/var/lib/dblab/dblab_pool/dump/rds_db.dump"
213+
dumpLocation: "/var/lib/dblab/dblab_pool/dump"
214214

215215
# The Docker image containing the tools required to restore.
216216
dockerImage: "postgresai/extended-postgres:13"
@@ -236,7 +236,7 @@ retrieval:
236236
# format: directory
237237
# # Option for a partial restore. Do not specify the tables section to restore all available tables.
238238
# tables:
239-
# - test
239+
# - table1
240240
# database2:
241241
# databaseN:
242242

pkg/retrieval/engine/postgres/logical/dump.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type Source struct {
9898
type DBDefinition struct {
9999
Tables []string `yaml:"tables"`
100100
Format string `yaml:"format"`
101+
dbName string
101102
}
102103

103104
type dumpJobConfig struct {
@@ -426,10 +427,12 @@ func (d *DumpJob) dumpDatabase(ctx context.Context, dumpContID, dbName string, d
426427
log.Msg("Partial dump will be run. Tables for dumping: ", strings.Join(dbDefinition.Tables, ", "))
427428
}
428429

429-
if err := d.performDumpCommand(ctx, dumpContID, types.ExecConfig{
430+
if output, err := d.performDumpCommand(ctx, dumpContID, types.ExecConfig{
431+
Tty: true,
430432
Cmd: dumpCommand,
431433
Env: d.getExecEnvironmentVariables(),
432434
}); err != nil {
435+
log.Dbg(output)
433436
return errors.Wrap(err, "failed to dump a database")
434437
}
435438

@@ -508,14 +511,12 @@ func (d *DumpJob) setupConnectionOptions(ctx context.Context) error {
508511
return nil
509512
}
510513

511-
func (d *DumpJob) performDumpCommand(ctx context.Context, contID string, commandCfg types.ExecConfig) error {
514+
func (d *DumpJob) performDumpCommand(ctx context.Context, contID string, commandCfg types.ExecConfig) (string, error) {
512515
if d.DumpOptions.Restore.Enabled {
513516
d.dbMark.DataStateAt = time.Now().Format(tools.DataStateAtFormat)
514517
}
515518

516-
_, err := tools.ExecCommandWithOutput(ctx, d.dockerClient, contID, commandCfg)
517-
518-
return err
519+
return tools.ExecCommandWithOutput(ctx, d.dockerClient, contID, commandCfg)
519520
}
520521

521522
func (d *DumpJob) getEnvironmentVariables(password string) []string {

0 commit comments

Comments
 (0)