OpenVPN Access Server backup and restore
Posted by Jared Thomas on 06 October 2016 10:53 AM

The following will create a backup of the OpenVPN Access Server databases that can be used to restore a configuration:

  1. Create the following script in /etc/cron.daily and make it executable:
    1. #!/bin/bash
      TODAY=$(date +%F)
      DIR=$(mktemp -d -t)
      /usr/local/openvpn_as/scripts/sqlite3  /usr/local/openvpn_as/etc/db/certs.db .dump > $DIR/certs.txt
      /usr/local/openvpn_as/scripts/sqlite3  /usr/local/openvpn_as/etc/db/config.db .dump > $DIR/config.txt
      /usr/local/openvpn_as/scripts/sqlite3  /usr/local/openvpn_as/etc/db/log.db .dump > $DIR/log.txt
      /usr/local/openvpn_as/scripts/sqlite3  /usr/local/openvpn_as/etc/db/userprop.db .dump > $DIR/userprop.txt
      /bin/tar -czvf $DEST/$TODAY.tar.gz $DIR/
      /usr/bin/find $DEST -type f -mtime +7 -delete
      rm -rf $DIR
      exit 0
  2. Adjust the DEST variable to change where the backup goes and make sure that DEST actually exists
  3. To change the length of time that the script retains backups, adjust the -mtime argument in the find command

To restore from one of these backups, follow these steps:

  1. extract the four text files from the backup
  2. stop the access server
  3. run the following command for each text file:
       /usr/local/openvpn_as/scripts/sqlite3 < file.txt /usr/local/openvpn_as/etc/db/file.db where file.txt is the text backup file and file.db is the database to be restored
  4. start the access server service

This process is tested on Ubuntu 16.04, adjustments may need to be made to paths, etc on different distros.


(0 vote(s))
Not helpful

Comments (0)
Post a new comment
Full Name:
CAPTCHA Verification 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).