Skip to content

Instantly share code, notes, and snippets.

@makenova
Last active March 1, 2024 18:13
  • Star 20 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save makenova/33fd38b6dbe0ec37d254 to your computer and use it in GitHub Desktop.
move pritunl between servers

Migrating your pritunl install between servers

This is a small write up about how to migrate your pritunl install between servers. It's not especially detailed because I'm lazy and your migration story will most likely be different. All this can be avoided by using a remote/hosted mongo instance(compose.io, mongolab, etc.) and simply pointing your pritunl instance at that. If you want more details ask, and I'll do my best to answer and update this write-up accordingly. Also, feel free to criticize my grammar and spelling.

Stop pritunl service

sudo service pritunl stop

Make a backup of current database

mongodump

Compress backup

tar -zcvf dump.tar.gz dump

Transfer backup archive to new server

scp dump.tar.gz user@remote-server:/path/to/save/location

Install pritunl on new server

  • save the following file on your server
  • make it executable chmod u+x pritunlInstall.sh
  • run it ./pritunlInstall.sh

For Ubuntu 14.04

#!/bin/bash
sudo tee -a /etc/apt/sources.list.d/mongodb-org-3.2.list << EOF
deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse
EOF

sudo tee -a /etc/apt/sources.list.d/pritunl.list << EOF
deb http://repo.pritunl.com/stable/apt trusty main
EOF

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 42F3E95A2C4F08279C4960ADD68FA50FEA312927
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 7568D9BB55FF9E5287D586017AE645C0CF8E292A
sudo apt-get update
sudo apt-get --assume-yes install pritunl mongodb-org
sudo service pritunl start

For Ubuntu 16.04

sudo tee -a /etc/apt/sources.list.d/mongodb-org-3.2.list << EOF
deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse
EOF

sudo tee -a /etc/apt/sources.list.d/pritunl.list << EOF
deb http://repo.pritunl.com/stable/apt xenial main
EOF

sudo tee -a /lib/systemd/system/mongod.service << EOF
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target
EOF

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 42F3E95A2C4F08279C4960ADD68FA50FEA312927
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 7568D9BB55FF9E5287D586017AE645C0CF8E292A
sudo apt-get update
sudo apt-get --assume-yes install pritunl mongodb-org
sudo systemctl start pritunl mongod
sudo systemctl enable pritunl mongod

Note: Both of the above scripts are available on the pritunl site in the install section. Simply select your distribution.

Unarchive compressed backup

tar -zxvf dump.tar.gz

Restore backup

mongorestore dump

Allow traffic

If you block traffic with a firewall you will need to make an exception for pritunl. The pritunl admin interface is on tcp:443 and each server you setup will also have a port that you will need to setup rules for. I use ufw as my firewall so ...

sudo ufw allow https

Test it out

Go to https://SERVER_IP and accept the prompt to use the local mongodb server. Then sign-in with your pritunl username and password from the previous server. If it all checks out, delete the old server and pat yourself on the back.

@Saturn-V
Copy link

have you managed to work around having to resupply the setup-key when restoring from a backup?

@makenova
Copy link
Author

Hello,
I have not. This is from years ago and may be is likely out of date.
If you figure out anything that is missing, I'll gladly update it or you can fork the gist and update that.
Best of luck!

@Saturn-V
Copy link

Fair enough. Haven't had any luck myself but if I find a resolution I'll be sure to leave an update here. thanks!

@jessecrossen
Copy link

You can skip having to enter the setup key by explicitly configuring the MongoDB URI as follows (replacing the URI if you're not using mongo on localhost):

sudo pritunl set-mongodb 'mongodb://localhost:27017/pritunl'

Official documentation is here. Make sure the server is stopped when you do this. Once you start it again, you should see the login dialog instead of the setup dialog.

@rhulet343
Copy link

rhulet343 commented May 26, 2020

You can also edit/replace the pritunl.conf file in /etc/pritunl.conf; also make sure the server is stopped when doing this.

{ "mongodb_uri": "mongodb://localhost:27017/pritunl", "log_path": "/var/log/pritunl.log", "static_cache": true, "temp_path": "/tmp/pritunl_%r", "bind_addr": "0.0.0.0", "www_path": "/usr/share/pritunl/www", "local_address_interface": "auto", "port": 443 }

@peppe77
Copy link

peppe77 commented Jun 11, 2021

Hi, currently stuck and in need of some suggestions. Restored snapshot volume (ec2/CentOS/pritunl) after trying upgrade - as to restore it to state prior to the uograde. Pritunl service is up and spawns all required processes except OpenVPN, therefore not able to vpn via this instance. The other 2 instances are fine. Check pritunl logs and didn't find anything that would explain why OpenVPN isn't started. Suggestions on what to check ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment