Backup and Restore Process

NOTE: This process works for OSP installations that are created within a Linux (Ubuntu) operating system. If you are using the Docker version of OSP then this document may not apply.

Overview

The backup and restore process involves taking a copy of the database, /var/www/ directory, and config.py file from an installation to another. This is useful in many cases such as broken in-place system upgrades and compromised infrastructure.

Requirements

  • A backup storage location greater than or equal to the amount of storage allocated to the current website’s.

  • Access to the current installation.

  • Access to the new “clean” installation.

Step 1: MySQL Backup

Create a saved copy of the current installation’s MySQL database using the mysqldump command, referenced here: (https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html)

sudo mysqldump -u [user] -p osp > osp.sql

Move this file to your backup storage. This can be done easily with FTP via a client such as Filezilla.

Step 2: config.py Backup

The next important piece to copy is the /opt/osp/conf/config.py file. This stores your Ejabberd and database keys as well as several important settings for your site.

Move this file to your backup storage. This can be done easily with FTP via a client such as Filezilla.

We will edit the values in this file later when we restore the installation. Make sure to keep the original in your backup as an unedited reference.

Step 3: /var/www/ Backup

The OSP program saves videos, site images, and other such data to the /var/www/ location on your (Ubuntu) operating system. To restore site content it is essential that this entire directory be saved. Depending on your site’s storage allocation this can be quite large.

Move this directory to your backup storage. This can be done easily with FTP via a client such as Filezilla.

Step 4: New Site Setup

At this point we have copied all required data to a separate, secure storage location.

If you are simply moving your OSP site from one physical system to another then this is the part where you can install OSP on the new system following the appropriate installation steps.

If you are wiping an existing computer and attempting to restore to a fresh installation then this is where you can wipe your existing system to a new OS. Again follow the provided installation instructions relevant to your setup. (Either single server or multi server installation, for the purposes of this guide these steps were performed on a single server installation.)

Once we have a fresh, working copy of OSP on the “fresh” system we should see a first time setup screen. Proceed with this, providing relevant details until you see a blank website.

NOTE: Do not leave your first time setup screen visible to the public internet, or someone may be able to fill in the details for you…

Step 5: Edit & Restore config.py

The config.py file referenced earlier has a particular variable in it called dblocation. This variable will be filled into your new site’s config.py file and will differ from the string contained in your backup version. The same difference exists for the Ejabberd password. These values are installation specific, generated by the installation process, and will need to be updated before the new system can use the old system’s data.

Backup an unedited version of config.py from the new system.

Replace the original backup’s version of the dblocation string and Ejabberd password with the new file’s version. Save this new (third) config.py and place it in the new system’s /opt/osp/conf location (replacing the config.py that exists there).

NOTE: If you need to you can update the Ejabberd password on the new system using the following command. This updated password can be placed into config.py after it is changed. (Backing up the config.py versions from both systems prevents the need for this)

sudo /usr/local/ejabberd/bin/ejabberdctl change_password admin localhost $ADMINPASS

Step 6: Restore the Database

Remove the new installation’s empty database using the following command.

DROP DATABASE [IF EXISTS] osp;

Move your saved database file from your backup location to the new installation.

Use the following command to restore your saved database. (Note that the command is basically the same as the backup command but with a “<” instead of a “>” denoting the direction of the data)

mysql -u [user] -p osp < osp.sql

Step 7: Restore /var/www

On the new installation purge the existing /var/www location and upload the backup version of this directory.

Step 8: Permissions Check

Verify that both the /opt/osp and /var/www directories are owned by www-data:www-data, if not, set the ownership.

Step 9: Reboot

Reboot the new system and you should see your restored website working on it.