Search by

journey / backup

justin-schroeder

Lightweight MySQL backup script for cron jobs, written in PHP.

Package info

github.com/journeygroup/backup

Homepage

Type:project

pkg:composer/journey/backup

Statistics

Installs: 22

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

0.1.2 2018-04-16 14:45 UTC

This package is not auto-updated.

Last update: 2026-09-13 01:50:20 UTC


README

Why

Journey/Backup is a lightweight MySQL backup script written in PHP, and ideal for cron jobs. Its task is simple:

  • Dump a user-selected list, or all databases on the local MySQL server
  • Store those databases in a mounted directory, or on Amazon S3

Usage

Installation

The easiest way is to install via composer:

composer create-project journey/backup your-directory-name

Configuration

Don't edit config.php directly — it's checked into git as the placeholder template. Instead, copy it to local.php and put your real details there:

cp config.php local.php

local.php is gitignored and, when present, boot.php loads it instead of config.php entirely (it's a full replacement, not a merge — local.php needs every key, not just the ones you're overriding). This keeps real credentials out of git history. Here's the sample configuration, with helpful comments:

<?php

return [
    // Nickname for the executing server
    'server' => 'server-name',

    // Local database connection details
    'connection' => [
        'host' => '127.0.0.1',
        'username' => 'mysql-username',
        'password' => 'mysql-password',
    ],

    // String of databases to back up, empty value will backup all databases
    'databases' => [],

    // Location of the storage, can be absolute directory or s3 stream (s3://bucket-name)
    'storage' => 's3://your-s3-bucket',

    // List of AWS Connection credentials
    'aws' => [
        'region' => 'us-east-1',
        'version' => '2006-03-01',
        'credentials' => [
            'key' => 'your-aws-key',
            'secret' => 'your-aws-secret',
        ],
    ],

    // Temporary location for dump
    'temp' => '/tmp'
];

Note: The host parameter is used only when databases is set to auto-discover all databases (empty array), otherwise all calls to MySQL are performed via shell operation.

Schedule

Scheduling your backups is as simple as setting up a cron job to execute the boot.php file.

By default boot.php backs up whatever databases is set to in local.php (or all databases, if it's empty). You can override that per-run by passing a database name as an argument — useful for running different databases on different schedules from the same config:

php boot.php your_database_name

For example, to back up a prod database hourly and a stage database once a day, both from the same local.php:

30 * * * * /usr/bin/php /var/www/backup/boot.php prod > /dev/null 2>&1
30 5 * * * /usr/bin/php /var/www/backup/boot.php stage > /dev/null 2>&1