wgrest
wgrest copied to clipboard
restore peers
hey... I backup the peers by ready api and stored into a file. he shows:
analpflaster:~/vpn/backup# cat interfaces/peers_150.json [ { "public_key": "HiCUb0B3yDHIl+0uI+2QhtOaWnLO3ld1CI3xINDcZEc=", "url_safe_public_key": "HiCUb0B3yDHIl-0uI-2QhtOaWnLO3ld1CI3xINDcZEc=", "allowed_ips": [ "172.1.4.1/32" ], "last_handshake_time": "0001-01-01T00:00:00Z", "persistent_keepalive_interval": "25s", "endpoint": "146.60.226.118:64096", "receive_bytes": 0, "transmit_bytes": 3996 } { "public_key": "5zaLcXXvX1zRD25jjwv0rNCcKqu6QocYuul5vUjkhFk=", "url_safe_public_key": "5zaLcXXvX1zRD25jjwv0rNCcKqu6QocYuul5vUjkhFk=", "allowed_ips": [ "172.1.4.2/32" ], "last_handshake_time": "0001-01-01T00:00:00Z", "persistent_keepalive_interval": "25s", "endpoint": "", "receive_bytes": 0, "transmit_bytes": 0 } ]
if I will restore it by using this json file I got an error:
{"message":"Syntax error: offset=350, error=invalid character '{' after array element"}
I used for restore: curl -iv POST -H 'Content-Type: application/json' -H "Authorization: Bearer $_key" -d @interfaces/peers_150.json $_api/$_interface1/peers/
Did you figure it out?
no, first was a format error. first I lost an ","
the correct format where:
} , {
but than I get an new think:
{ "message": "Unmarshal type error: expected=models.PeerCreateOrUpdateRequest, got=array, field=, offset=1" }
i don't know what's the correct way
@muplagama As of now, the feature to support arrays isn't available. However, we're open to contributions! Feel free to submit a PR if you'd like to add this functionality.
I dont know... for next time will get it over bash and a simple list to backup it.
curl -X 'GET'
"$_api/$_interface1/peers/"
-H 'accept: application/json'
-H "Authorization: Bearer $_key" | jq -r '.[]' | grep "url_safe_public_key" | awk '/url_safe_public_key/ {print $2}'| cut -c2- | sed 's/.$//' | sed 's/.$//' > interfaces/peers/all_150.json
xxx:~/vpn/backup# cat interfaces/peers/all_150.json HiCUb0B3yDHIl-0uI-2QhtOaWnLO3ld1CI3xINDcZEc= ks0FrWFgZIufSM5k0HMCDcYOlTyiouDRfEAo_OGX9C8=
and after I send a request with every url_save_public_key to save an json for every peer..
@muplagama Yes, that's one way to do it. Alternatively, you could restore peers using the wg-quick file and wg-quick tools.
what do you mean
You can export the configuration to the /etc/wireguard/wg0.conf file, and then use the wg-quick tool to restore it.
ok, but I think a restore via the API is better :)