Skip to content

Commit a2e5f02

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 daef549 commit a2e5f02

File tree

2 files changed

+51
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)