Recovering From Backup Data - Lookaway CMS

Documented by Kyle Bruder on Mar 08, 2021
Last updated on Mar 23, 2021

Lookaway Logo


This document explains how to recover your Lookaway CMS powered website from backup data. Sometimes things can go very wrong resulting in a loss of data on your websever. It happens to the best. The only data that matters to Lookaway CMS are the source code, the database, and the media storage.

The best data stewards always keep regular backups. The more more often you backup your data, the less data you will loose. For example, if you do full backup of the database and media files on the first of every month at 4:00 AM, and the web server data is lost on the 31st of October, you will loose any new data created after October 1st 4:00 AM which represents 30 days of data (and likely a lot of work). How often you backup your data should be determined by how critical the data is and may be required to adhere to government regulations. This site backs up its data once every 24 hours.

Ideally, you should not rely solely on back up data to keep your data available. Highly available filesystems and databases, if properly configured and leveraged, should suffice. However, websites operating on low budgets or ones that are subjects to frequent attacks may need to be rebuilt from scratch. This guide will explain the process.

  1. Prerequisites

    This guide assumes that you have a backup database dump file and a gzipped tape archive of a the corresponding media directory. The users, file paths and database names used in the example code are intended to be consistent with other examples on the site in order to avoid the use of meta syntax.

    Simple Backup Scheme - Lookaway CMS

    Learn how to automatically backup your Lookaway media and database once per day and remove backups older than one week using Ubuntu and PostgreSQL.

  2. Check Disk Space on Mounted Linux Filesystems

    Before doing anything else, make sure you have enough storage to perform a recovery. In this example, we have two LVM volumes mounted. One is mounted to '/home/lookaway/backups' and the other is mounted to '/home/lookaway/lookaway-env/lookaway/media'. The 'du' command shows the disk usage for a file or multiple files. Do the arithmetic in order to determine if your filesystem can hold your existing data and a copy that may be larger than what you currently have. Here there is plenty of space left on both volumes.

    $ df -h
    Filesystem                Size  Used Avail Use% Mounted on
    /dev/mapper/raid0         984G  7.7G  926G   1% /home/lookaway/lookaway-env/lookaway/media
    /dev/mapper/backups       2.0T   60G  1.8T   4% /home/lookaway/backups
    $ du -sh ~lookaway/lookaway-env/lookaway/media
    7.7G	/home/lookaway/lookaway-env/lookaway/media

  3. Stop the Lookaway Service

    Use the following command to stop the Lookaway code from running.

    Tip: If possible, send out a message to your members and site visitors letting them know when you will be performing the recovery.

    Caution: Stopping the Lookaway service will cause the site to become unavailable.

    # Stop the Lookaway app
    $ sudo systemctl stop lookaway.service

    Stop the Lookaway Service.

  4. Fetch the Backup Data

    #         # Use your backup path here
    $ cp backups/<YYYY-MM-DD>/media.tar.gz .
    $ cp backups/<YYYY-MM-DD>/lookaway.sql.gz .
    $ gunzip lookaway.sql.gz

    Source: kbruder Tech

  5. Replace the Media Directory

    Use the following command to extract the files. As long as you are using a tar archive that was created with absolute paths (as with the backup script provided with the Lookaway code repository) you can use this command from any directory. If you made a backup archive using a relative path then omit the -C flag and run the command from the base directory.

    Tip: If you extract the files and they end up in the wrong directory, simply use the 'mv' command to move then to the correct location.

    # Check to see if the path is absolute or relative.
    tar tvf backups/21-03-15/lookaway_media.tar.gz | head
    drwxr-xr-x lookaway/lookaway 0 2021-02-25 12:06 home/lookaway/lookaway-env/lookaway/media/
    # We can see that it is realtive to root (absolute) given a typical Linux filesystem.
    # Replace the media filesystem
    #                                   # Use your lookaway media dir path here 
    $ tar xvfpz media.tar.gz -C / /home/lookaway/lookaway-env/lookaway/media

  6. Replace the Database

    Use the following commands to replace the Lookaway database. In order to do this, we must first remove the existing database then add an empty database of the same name, grant the privileges to the Lookaway user then import the backup data.

    Tip: If you have space, you might want to back up your current database, even if it is not working.

    # Remove the current database
    $ dropdb lookaway
    # Replace the database
    $ createdb lookaway
    $ psql
    lookaway=> grant all privileges on database lookaway to lookaway;
    lookaway=> \q
    #        #Linux usr      #PSQL user #DB name
    $ psql lookaway < lookaway.sql

    Source: kbruder Tech

    Lookaway CMS Database Configuration - Postgresql 10

    Learn how to configure a Postgresql database and role for use with Lookaway CMS

  7. Start the Lookaway Service

    Restart the Lookaway service. If all is well, the site should become available again.

    # Start the Lookaway app
    $ sudo systemctl start gunicorn
    # Check to the status
    $ sudo systemctl status lookaway
     lookaway.service - lookaway gunicorn daemon
         Loaded: loaded (/etc/systemd/system/lookaway.service; enabled; vendor preset: enabled)
         Active: active (running) since Wed 2021-03-17 20:17:15 PDT; 4 days ago

    Source: kbruder Tech

  8. Cleanup

    Once the recovery is confirmed to be successful, remove the backup files that were fetched earlier.

    $ rm lookaway.sql media.tar.gz

Bitcoin Accepted Here


Please donate some Bitcoin to our site. We can use it to keep improving the site and open up to more members. Any amount will help. Thank you.

Litecoin Accepted Here


Please donate some Lite to our site. We can use it to keep improving the site and open it up to more members. Any amount will help. Thank you.