Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore peers #35

Open
muplagama opened this issue Dec 31, 2023 · 8 comments
Open

restore peers #35

muplagama opened this issue Dec 31, 2023 · 8 comments

Comments

@muplagama
Copy link

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/

@Sajeyks
Copy link

Sajeyks commented Jan 5, 2024

Did you figure it out?

@muplagama
Copy link
Author

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

@suquant
Copy link
Owner

suquant commented Jan 5, 2024

@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.

@muplagama
Copy link
Author

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..

@suquant
Copy link
Owner

suquant commented Jan 5, 2024

@muplagama Yes, that's one way to do it. Alternatively, you could restore peers using the wg-quick file and wg-quick tools.

@muplagama
Copy link
Author

what do you mean

@suquant
Copy link
Owner

suquant commented Jan 5, 2024

You can export the configuration to the /etc/wireguard/wg0.conf file, and then use the wg-quick tool to restore it.

@muplagama
Copy link
Author

ok, but I think a restore via the API is better :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants