Copy wireguard peers between devices with uci

Need to transfer wireguard peers to new router. Did "uci show" on the old device and used it's output to generate "uci set" lines for the new one. However pasting them on the new router gives me:

root@gate:~# uci set "network.@wireguard_wg0[1]=wireguard_wg0"
root@gate:~# uci set "network.@wireguard_wg0[1].description='Peer1'"
uci: Invalid argument
......

and same "uci: Invalid argument" for all other lines but the "=wireguard_wg0" ones. What am i doing wrong?

My question is where was i wrong while working wuth uci, as for the peers, transfered them by editing /etc/config/network

Wireguard configurations happen almost exclusively within /etc/config/network (plus firewalling rules/ routing information in /etc/config/firewall). If you replace the old device with a new one, you can copy'n'paste the wireguard specific configuration stanzas betweem both devices using your preferred text editor, this is going to be easier than ucion cli.

Just be aware that wireguard keys mustn't be reused, as they are part of the wireguard connection - so if you copy them over from another device, make sure that the old device never gets online again (without resetting all wireguard configuration first or at least generating new keys throughout).

1 Like

So you to don't know how to edit "uci show" dumps to turn them into valid command lines. Still if somebody else knows, please advice. While with transferring wireguard peers it was easy to find alternative way, generally there are just to many cases where it is preferable to know how to do it using uci.

Copying the stanzas from /etc/config/network is absolutely the simplest way to achieve the goal of transferring peers from one device to another. Trying to do it with uci is just making life difficult for yourself.

It's probably easier to script something to parse the config and pull out the Wireguard stanzas (the file is incredibly simple to parse in this respect) than it is to manually get the peer configurations with uci, reformat them, and then re-enter them with uci again.