Skip to content

Commit 17804b9

Browse files
committed
cmd/loop: add recover command for local backups
Expose the new recovery flow through loop-cli with a dedicated recover command that calls loopd over the existing RPC connection and optionally accepts a custom backup file path.
1 parent 95beb88 commit 17804b9

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

cmd/loop/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ var (
8888
monitorCommand, quoteCommand, listAuthCommand, fetchL402Command,
8989
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
9090
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
91-
getInfoCommand, abandonSwapCommand, reservationsCommands,
91+
getInfoCommand, abandonSwapCommand, recoverCommand,
92+
reservationsCommands,
9293
instantOutCommand, listInstantOutsCommand, stopCommand,
9394
printManCommand, printMarkdownCommand,
9495
}

cmd/loop/recover.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"context"
5+
6+
"github.com/urfave/cli/v3"
7+
"google.golang.org/protobuf/types/known/structpb"
8+
"google.golang.org/protobuf/types/known/wrapperspb"
9+
)
10+
11+
var recoverCommand = &cli.Command{
12+
Name: "recover",
13+
Usage: "restore static address and L402 state from a local backup file",
14+
Description: "Restores the local static-address state and L402 token " +
15+
"from an encrypted backup file. If --backup_file is omitted, " +
16+
"loopd will use the latest timestamped network-specific backup " +
17+
"file.",
18+
Flags: []cli.Flag{
19+
&cli.StringFlag{
20+
Name: "backup_file",
21+
Usage: "path to an encrypted backup file; if omitted, " +
22+
"loopd uses the latest timestamped backup file path",
23+
},
24+
},
25+
Action: runRecover,
26+
}
27+
28+
func runRecover(ctx context.Context, cmd *cli.Command) error {
29+
if cmd.NArg() > 0 {
30+
return showCommandHelp(ctx, cmd)
31+
}
32+
33+
_, conn, cleanup, err := getClientWithConn(cmd)
34+
if err != nil {
35+
return err
36+
}
37+
defer cleanup()
38+
39+
resp := &structpb.Struct{}
40+
err = conn.Invoke(
41+
ctx, "/looprpc.Recovery/Recover",
42+
wrapperspb.String(cmd.String("backup_file")), resp,
43+
)
44+
if err != nil {
45+
return err
46+
}
47+
48+
printJSON(resp.AsMap())
49+
return nil
50+
}

0 commit comments

Comments
 (0)