1
0
Fork 0

Add .dump to CLI

master
Philip O'Toole 5 years ago
parent a123b29d32
commit 76975f96fe

@ -1,6 +1,7 @@
## 4.6.0 (unreleased) ## 4.6.0 (unreleased)
- [PR #591](https://github.com/rqlite/rqlite/pull/591): Store layer supports generating SQL format backups - [PR #592](https://github.com/rqlite/rqlite/pull/592): Add .dump to CLI.
- [PR #590](https://github.com/rqlite/rqlite/pull/590): DB layer supports generating SQL format backups - [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 #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 #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. - [PR #587](https://github.com/rqlite/rqlite/pull/587): Add expvar stats to store.

@ -62,6 +62,29 @@ func backup(ctx *cli.Context, filename string, argv *argT) error {
return nil 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) { func makeRestoreRequest(restoreFile io.Reader) func(string) (*http.Request, error) {
return func(urlStr string) (*http.Request, error) { return func(urlStr string) (*http.Request, error) {
req, err := http.NewRequest("POST", urlStr, restoreFile) req, err := http.NewRequest("POST", urlStr, restoreFile)

@ -33,9 +33,10 @@ const cliHelp = `.help Show this message
.status Show status and diagnostic information for connected node .status Show status and diagnostic information for connected node
.expvar Show expvar (Go runtime) information for connected node .expvar Show expvar (Go runtime) information for connected node
.tables List names of tables .tables List names of tables
.timer on|off Turn SQL timer on or off .timer on|off Turn query timer on or off
.backup <file> Write database backup to file .dump <file> Dump the database in SQL text format to a file
.restore <file> Restore the database from a SQLite dump file .restore <file> Restore the database from a SQLite dump file
.backup <file> Write database backup to SQLite file
` `
func main() { func main() {
@ -102,6 +103,12 @@ func main() {
break break
} }
err = restore(ctx, line[index+1:], argv) 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": case ".HELP":
err = help(ctx, cmd, line, argv) err = help(ctx, cmd, line, argv)
case ".QUIT", "QUIT", "EXIT": case ".QUIT", "QUIT", "EXIT":

Loading…
Cancel
Save