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

Backup restore procedure can load aws config #8962

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions go/libraries/doltcore/sqle/dprocedures/dolt_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ func restoreBackup(ctx *sql.Context, _ env.DbData, apr *argparser.ArgParseResult

sess := dsess.DSessFromSess(ctx.Session)

remoteParams := map[string]string{}
r := env.NewRemote("", backupUrl, remoteParams)
params, err := loadAwsParams(ctx, sess, apr, backupUrl, "restore")
if err != nil {
return err
}

r := env.NewRemote("", backupUrl, params)
srcDb, err := r.GetRemoteDB(ctx, types.Format_Default, nil)
if err != nil {
return err
Expand Down Expand Up @@ -236,24 +240,19 @@ func removeBackup(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseRe
}
}

func syncBackupViaUrl(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSession, apr *argparser.ArgParseResults) error {
if apr.NArg() != 2 {
return fmt.Errorf("usage: dolt_backup('sync-url', BACKUP_URL)")
}

backupUrl := strings.TrimSpace(apr.Arg(1))
func loadAwsParams(ctx *sql.Context, sess *dsess.DoltSession, apr *argparser.ArgParseResults, backupUrl, backupCmd string) (map[string]string, error) {
cfg := loadConfig(ctx)
scheme, absBackupUrl, err := env.GetAbsRemoteUrl(filesys.LocalFS, cfg, backupUrl)
if err != nil {
return fmt.Errorf("error: '%s' is not valid.", backupUrl)
return nil, fmt.Errorf("error: '%s' is not valid.", backupUrl)
} else if scheme == dbfactory.HTTPScheme || scheme == dbfactory.HTTPSScheme {
// not sure how to get the dialer so punting on this
return fmt.Errorf("sync-url does not support http or https backup locations currently")
return nil, fmt.Errorf("%s does not support http or https backup locations currently", backupCmd)
}

params, err := cli.ProcessBackupArgs(apr, scheme, absBackupUrl)
if err != nil {
return err
return nil, err
}

credsFile, _ := sess.GetSessionVariable(ctx, dsess.AwsCredsFile)
Expand All @@ -274,6 +273,20 @@ func syncBackupViaUrl(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSessi
params[dbfactory.AWSRegionParam] = regionStr
}

return params, nil
}

func syncBackupViaUrl(ctx *sql.Context, dbData env.DbData, sess *dsess.DoltSession, apr *argparser.ArgParseResults) error {
if apr.NArg() != 2 {
return fmt.Errorf("usage: dolt_backup('sync-url', BACKUP_URL)")
}

backupUrl := strings.TrimSpace(apr.Arg(1))
params, err := loadAwsParams(ctx, sess, apr, backupUrl, "sync-url")
if err != nil {
return err
}

b := env.NewRemote("__temp__", backupUrl, params)

return syncRootsToBackup(ctx, dbData, sess, b)
Expand Down
Loading