Symptoms

An APS 1.2 of Shared type (Site Application) was accidentally de-provisioned from a subscription. How to restore the application to the previous working state?

Resolution

Restoration requirements:

  • available backup of the webspace from the date before the accident
  • available backup of the application database

Step-by-step procedure for a single subscription, ID 1000001 is used as an example.

  1. Get the webspace ID of the subscription in PCP > Services > Web Hosting > Apache Webspaces. Alternatively it can be fetched by pem.getWebspacesList API call. getWebspacesList.py script may help:

    [root@osscore ~]# python getWebspacesList.py 1000001
    2016-10-04 21:00:39.460 DEBUG call method pem.getWebspacesList({'subscription_id': 1000001, 'txn_id': '1434510598'})
    2016-10-04 21:00:40.008 DEBUG return {'status': 0, 'result': [{'path': '/var/www/vhosts/100001/', 'webspace_id': 100001, 'domain_id': 3, 'host_ip': '203.0.113.2', 'domain_name': 'example.com'}]}
    2016-10-04 21:00:40.060  INFO Subscription 1000001 webspaces are:
    100001
    

    Note: there is 1 webspace per subscription in the majority of cases, so 1 entry is returned as a result of the API call. But in some rare cases, there could be more than 1 webspaces.

  2. Check APS package version in the webspace backup:

    [root@web1 ~]# egrep '<version>|<release>' 12321/backup/siteapps/MyApp-12321/APP-META.xml
            <version>1.0.1</version>
            <release>4</release>
    

    In case the version does not match the current top enabled version as seen in PCP > Services > Applications > MyApp > Versions, then disable all versions higher than the required one. Revert these changes after step 4.

  3. Make sure the resource limit for this APS application is not 0 and allows installing it.
  4. Login to CCP > Websites > example.com > Web Applications > Install, pick MyApp.
  5. Determine the configuration file to get the details of the application database on the newly provisioned instance. Go to CCP > More Services > Databases, pick the database that was created most recently, its name is formed as db<subscription_id>_sa<app_instance_id>, example: db1000001_sa12322. Then search for this name in the file hierarchy of the application:

    # grep -l db1000001_sa12322 /var/www/vhosts/1/100001/siteapps/MyApp-12322/*
    /var/www/vhosts/1/100001/siteapps/MyApp-12322/htdocs/config.php
    

    Get the DB access details from this file:

    define('DB_SERVER', '192.0.2.2');
    define('DB_USERNAME', 'u1000001_sa12322');
    define('DB_PASSWORD', 'password');
    define('DB_DATABASE', 'db1000001_sa12322_main');
    

    Note: different applications may have similar definition data stored in different files and in different format.

  6. Restore the old application instance database backup into the newly created database. Make sure that the database dump does not include CREATE DATABASE $db_name and USE $db_name lines.

    # mysql -u u1000001_sa12321 -p'password' db1000001_sa12322_main < db1000001_sa12321_main.sql
    
  7. Back up the DB definition configuration file and restore the content of the site application files from the webspace backup:

    # cp -arf /var/www/vhosts/1/100001/siteapps/MyApp-12322/htdocs/config.php MyApp-12322.config.php
    # cp -arf /path/to/webspace/backup/siteapps/MyApp-12321/* /var/www/vhosts/1/100001/siteapps/MyApp-12322/
    # cp -arf MyApp-12322.config.php /var/www/vhosts/1/100001/siteapps/MyApp-12322/htdocs/config.php
    

    Note: in case of several configuration files with DB access definition, backup them all before restoring files and put them back afterwards

  8. Make sure the permissions are correct for the restored files:

    [root@web1 ~]# ls -ald /var/www/vhosts/1/100001/webspace/httpdocs
    drwxr-x--- 3 a100001 pemsrv 4096 Oct  3 16:29 /var/www/vhosts/1/100001/webspace/httpdocs
    
    [root@web1 ~]# chown -R a100001:pemcln /var/www/vhosts/1/100001/webspace/siteapps/MyApp-12322
    
  9. Reset the application admin user password in CCP > Websites > example.com > Web Applications > MyApp > Configure > Generate > Submit.

  10. In case of non-default URL path, it can be configured according to the backup files. The configuration will usually be stored in config.php or a similar file, e.g.:

    define('BASE_URL', 'http://example.com');
    define('DIR_REL', '/MyApp');
    

Internal content