Recipe "Easy System Cloning (DSESC) Restore"

From SMW CindyKate - Main
Component 998880
Jump to: navigation, search

Content

HasGitHubRepository https://github.com/dataspects/EasySystemCloning DSESC Restore

Resources

Goal

This setup allows you to restore a SMW into your local copy of LCC's Standard SMW Vagrant Box. This approach allows you to restore your last backup into a working local copy of your SMW within minutes (depending on the number of backup increments and your internet connection speed) for

Server Setup

See Recipe "Easy System Cloning (DSESC) Backup"

Local Setup

On your workstation

  1. vagrantup.com Add the Vagrant Box LinuxCompetenceCenter/ch.l-c-c.standard-smw, see Repository "Vagrant Boxes on Hashicorp Atlas"
  2. galaxy.ansible.com/LinuxCompetenceCenterGalaxy Add the Ansible Role LinuxCompetenceCenterGalaxy.lcc-smw-duplicity-restore, see Repository "Ansible Roles on Ansible Galaxy"
  3. Set up the following structure based on the SMW Factory Components below.
[email protected]:~/workspace$ tree
.
├── ansible.cfg                       # See https://docs.ansible.com/ansible/intro_configuration.html
├── restore_smw.playbook              # Specifies Ansible role to play and post-role tasks
├── restore_smw_templates
│   ├── 000-default.conf.j2           # Configures the restored SMW's Apache virtual host
│   └── refresh_restored_smw.sh.j2    # Script for refreshing the restored SMW
├── Vagrantfile                       # Configures the VM
└── variables.yml                     # Encrypted file for configuring the restoration

SMW Factory Components

Ansible Configuration File "ansible.cfg"


[ssh_connection]
pipelining = true

referred by

Ansible Role "lcc-smw-duplicity-restore"



referred by

variables.yml

  • ACTION REQUIRED Since this file contains sensitive information about accessing your remote location as well as for decrypting your backup sets, it is strongly advised to encrypt this file using Ansible Vault. The Vault password set must then be entered whenever running the restore process.

---

# NO TRAILING SLASHES!

lsdr_restoring_os_user: restoreuser
lsdr_restoring_db_name: restoreuser

lsdr_duplicity_restore_script: restore_from_amazon_s3.sh
lsdr_amazon_s3_bucket_url: s3://s3.amazonaws.com/
lsdr_duplicity_restore_path: /home/restoreuser/restore

lsdr_aws_access_key_id: 
lsdr_aws_secret_access_key: 
lsdr_gnupg_secret_passphrase: 

lsdr_restored_smw_root: /home/restoreuser/restore
lsdr_restored_smw_dump_sql: /home/restoreuser/restore/smw_dump.sql

lsdr_apache_smw_root: /var/www/html/m

lsdr_public_gpg_key: |
  -----BEGIN PGP PUBLIC KEY BLOCK-----
  Version: GnuPG v1
  -----END PGP PUBLIC KEY BLOCK-----
lsdr_secret_gpg_key: |
  -----BEGIN PGP PRIVATE KEY BLOCK-----
  Version: GnuPG v1
  -----END PGP PRIVATE KEY BLOCK-----

referred by

restore_smw_templates/

It will allow you to refresh easily by vagrant ssh'ing into the VM and run /home/restoreuser/refresh_restored_smw.sh.

000-default.conf.j2

<VirtualHost *:80>
	ServerAdmin [email protected]
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /var/www/html>
                RewriteEngine On
                Options FollowSymLinks
                AllowOverride None
                RewriteRule ^/?main(/.*)?$ {{lsdr_apache_smw_root}}/index.php [L]
        </Directory>
</VirtualHost>

refresh_restored_smw.sh.j2

#!/bin/sh

php {{lsdr_apache_smw_root}}/maintenance/runJobs.php
php {{lsdr_apache_smw_root}}/maintenance/rebuildall.php
php {{lsdr_apache_smw_root}}/extensions/SemanticMediaWiki/maintenance/rebuildData.php
php {{lsdr_apache_smw_root}}/extensions/Cargo/maintenance/cargoRecreateData.php

referred by

restore_smw.playbook


---

- hosts: all
  sudo: True
  gather_facts: False
  vars_files:
    - variables.yml
  roles:
    - LinuxCompetenceCenterGalaxy.lcc-smw-duplicity-restore
  post_tasks:
    - name: Update {{lsdr_restoring_os_user}} mysql user's password in LocalSettings.php
      lineinfile: dest={{lsdr_apache_smw_root}}/LocalSettings.php
        regexp='^\$wgDBpassword'
        line="$wgDBpassword = parse_ini_file('/home/{{lsdr_restoring_os_user}}/.my.cnf',true)['client']['password'];"
    - name: Create 000-default.conf
      template: src=restore_smw_templates/000-default.conf.j2
        dest=/etc/apache2/sites-available/000-default.conf
        owner=root
        group=root
        mode=0644
      notify:
        - restart apache
        - restart mysql
    - name: Create refresh_restored_smw.sh
      template: src=restore_smw_templates/refresh_restored_smw.sh.j2
        dest=/home/{{lsdr_restoring_os_user}}/refresh_restored_smw.sh
        owner={{lsdr_restoring_os_user}}
        group={{lsdr_restoring_os_user}}
        mode=0744

referred by

Vagrantfile


# -*- mode: ruby -*-
# vi: set ft=ruby :
 
Vagrant.configure(2) do |config|
  config.vm.define "restore_smw" do |fwr|
 
    fwr.vm.box_check_update = false
    fwr.vm.box = "LinuxCompetenceCenter/ch.l-c-c.standard-smw"
    fwr.vm.box_version = "0.0.1"
 
    fwr.vm.hostname = "RestoredSMW"
 
    fwr.vm.provider "virtualbox" do |vb|
      vb.name = "Restored SMW"
      vb.memory = 1024
      vb.cpus = 2
    end
 
    fwr.vm.network "forwarded_port", guest: 22, host: 20090
    fwr.vm.network "forwarded_port", guest: 80, host: 20091
 
    fwr.vm.provision "ansible" do |ansible|
      ansible.ask_vault_pass = true
      ansible.playbook = "restore_smw.playbook"
    end
 
  end
 
end

referred by
time vagrant up