Skip to content

Instantly share code, notes, and snippets.

@Weingartens
Forked from makenova/pritunlMigration.md
Created March 1, 2024 18:13
Show Gist options
  • Save Weingartens/21898003c3f1c6bce33aef4b44c3408e to your computer and use it in GitHub Desktop.
Save Weingartens/21898003c3f1c6bce33aef4b44c3408e 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.

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