diff --git a/CHANGELOG.md b/CHANGELOG.md index 57c532de..77d42c2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 4.6.0 (unreleased) -- [PR #591](https://github.com/rqlite/rqlite/pull/591): Store layer supports generating SQL format backups -- [PR #590](https://github.com/rqlite/rqlite/pull/590): DB layer supports generating SQL format backups +- [PR #592](https://github.com/rqlite/rqlite/pull/592): Add .dump to CLI. +- [PR #591](https://github.com/rqlite/rqlite/pull/591): Store layer supports generating SQL format backups. +- [PR #590](https://github.com/rqlite/rqlite/pull/590): DB layer supports generating SQL format backups. - [PR #589](https://github.com/rqlite/rqlite/pull/589): Add restore command to CLI. Thanks @eariassoto. - [PR #588](https://github.com/rqlite/rqlite/pull/588): Abort transaction if load operation fails. - [PR #587](https://github.com/rqlite/rqlite/pull/587): Add expvar stats to store. diff --git a/cmd/rqlite/backup.go b/cmd/rqlite/backup.go index 690d6703..84ba90cf 100644 --- a/cmd/rqlite/backup.go +++ b/cmd/rqlite/backup.go @@ -62,6 +62,29 @@ func backup(ctx *cli.Context, filename string, argv *argT) error { return nil } +func dump(ctx *cli.Context, filename string, argv *argT) error { + queryStr := url.Values{} + queryStr.Set("fmt", "sql") + u := url.URL{ + Scheme: argv.Protocol, + Host: fmt.Sprintf("%s:%d", argv.Host, argv.Port), + Path: fmt.Sprintf("%sdb/backup", argv.Prefix), + RawQuery: queryStr.Encode(), + } + response, err := sendRequest(ctx, makeBackupRequest, u.String(), argv) + if err != nil { + return err + } + + err = ioutil.WriteFile(filename, *response, 0644) + if err != nil { + return err + } + + ctx.String("SQL text file written successfully\n") + return nil +} + func makeRestoreRequest(restoreFile io.Reader) func(string) (*http.Request, error) { return func(urlStr string) (*http.Request, error) { req, err := http.NewRequest("POST", urlStr, restoreFile) diff --git a/cmd/rqlite/main.go b/cmd/rqlite/main.go index 3ad294ca..c407fb72 100644 --- a/cmd/rqlite/main.go +++ b/cmd/rqlite/main.go @@ -33,9 +33,10 @@ const cliHelp = `.help Show this message .status Show status and diagnostic information for connected node .expvar Show expvar (Go runtime) information for connected node .tables List names of tables -.timer on|off Turn SQL timer on or off -.backup Write database backup to file +.timer on|off Turn query timer on or off +.dump Dump the database in SQL text format to a file .restore Restore the database from a SQLite dump file +.backup Write database backup to SQLite file ` func main() { @@ -102,6 +103,12 @@ func main() { break } err = restore(ctx, line[index+1:], argv) + case ".DUMP": + if index == -1 || index == len(line)-1 { + err = fmt.Errorf("Please specify an output file for the SQL text") + break + } + err = dump(ctx, line[index+1:], argv) case ".HELP": err = help(ctx, cmd, line, argv) case ".QUIT", "QUIT", "EXIT":