The Plan B

Let's talk about backups

TYPO3 UserGroup Cologne // September 20th, 2017 // Zephir Digital GmbH

Who's speaking?

Marcel
aka. nikonierer

Software Developer

* '86

TYPO3 since '08

TYPO3 CMS Certified Unicorn

Hockey
(Kölner Haie, Tampa Bay Lightning)

Theme parks, coaster counter (54)

The five

W's

What

to back up?

Why

to back up?

When

to back up?

Where

to back up?

Wow

to back up?

How

to back up?

Let's backup...

what?

Full backups

Differential backups

Incremental backups

Let's go full strength

RAID != Backup

Restore data loss

Recover
earlier
versions

Scheduled

On change

Cloud

Own infrastructure

Let's use
already
known tools!

Let's
surf!

What we did...

Backup solution...

...based on TYPO3 Surf

Defined new backup workflow

Implemented own tasks where needed

Used existing tasks when possible

Scheduled backups using cronjob

On change backups using existing CI workflow

Custom trigger by using shell scripts

many more...

New tasks

Dump
Database

Collect
Files

Create
Directories

Cleanup
Transfer
Cache

Local
Gzip

Symlink

Rsync

Rsync
Database
Dump

Direct
Rsync

Backup workflow

Stages

Initialize
Initialize directories (first time backup)

Collect Files
Collect files to backup

Database
Create database dump

Stages Part 2

Package
Local preparation of backup package

Transfer
Transfer package to backup machine

Finalize
Cleanup

Example backup configuration

<?php
$workflow = new \ZD\SurfBackups\Domain\Model\BackupWorkflow();
$node = new \ZD\SurfBackups\Domain\Model\Node('gks-rechtsanwaelte.de');
$node->setHostname('gks-rechtsanwaelte.de');
$node->setOption('username', 'ssh-usermame');
					
$node->setOption('databaseHost', 'localhost');
$node->setOption('databaseUsername', 'db-username');
$node->setOption('databasePassword', 'secret-password');
$node->setOption('databaseName', 'db-name');
$node->setOption('databaseGzipCompression', true);
					
$application = new \ZD\SurfBackups\Domain\Model\Application('typo3');
// Represents backup folder excluding application name and release folder
$application->setBackupBasePath('/home/backup/surf-backups/');
$application->setBackupSourcePath('/path/to/document-root/web');
$application->addNode($node);
					
/** @var \ZD\SurfBackups\Domain\Model\Backup $deployment */
$deployment->setWorkflow($workflow);
$deployment->addApplication($application);
$deployment->setBackupWorkspacesPath('.surf');
					

Example (basic) shell script integration

#!/bin/bash

dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

echo "Start parsing directory ${dir}/backups/"

for backup in ${dir}/backups/*.php
do
    echo "Backing up: ${backup}"

    file="${backup##*/}"
    ${dir}/bin/backup backup $(echo ${file} | cut -d'.' -f 1) >> ./log/backups.log
done
                    

Advantages
(from our perspective)

Known toolset

Flexible and extendable

It's PHP

Easy to learn

Lessons learned

TYPO3 surf not as flexible as expected

Implementation of own CLI command and executable needed

Misleading wording due to missing flexibility

One More Thing

From production
to development
back to production

From production
to development
back to production

From production

to backup

to development

Questions?

Credits

Used images

Slide 3-9 // Slide 10 // Slide 13 // Slide 17 // Slide 20 // Slide 23 // Slide 25 // Slide 48 // Slide 49 & 50 // Slide 54 // Slide 55

References

TYPO3 Surf @ github // Talk about TYPO3 Surf @ TUGCGN (outdated) // Surf backups @ github