• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    PHP
  • Created about 11 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A database backup package.

This package is abandoned. This Backup Manager has fully replaced it.

Database Backup

A framework-agnostic database backup package.

Drivers: At this moment the package supports MySQL, gzip, and Amazon S3. However, it's modular and could be extended to support much more.

Frameworks: This package doesn't require a framework, but a Laravel service provider and Artisan command are made available for convenience.

Note: be aware that this package uses mysqldump for MySQL backups.

Example

Laravel users can run the following command if they'd like to backup the db, gzip it, upload it to s3, and remove the local backup file:

php artisan db:backup --s3-bucket=whatever --s3-path=/this/is/optional/ --cleanup --gzip

Non-Laravel users can look at the Usage section below.

Requirements

  • 5.4 (would openly accept pull requests to lower to 5.3)

Installation

Laravel

  1. add to composer.json

    "mccool/database-backup": "1.0.1"
  2. install dependency

    composer update
  3. install configuration file

    php artisan config:publish mccool/database-backup
  4. add service provider to config/app.php

    'McCool\DatabaseBackup\ServiceProviders\LaravelServiceProvider',
  5. add key / secret to the config file in app/config/packages/mccool/database-backup/aws.php

Native PHP

  1. add to composer.json

    "mccool/database-backup": "dev-master"
  2. install dependency

    composer update
  3. make sure that your app requires the composer autoloader

    require '../vendor/autoload.php';

Usage

Laravel

Dump the database to app/storage/dumps/databasename_timestamp.sql

php artisan db:backup

Store the database to backups/databasename_timestamp.sql

php artisan db:backup --local-path=backups

Gzip the database.

php artisan db:backup --gzip

Choose a database to dump other than the default (names are configured in Laravel's config/database.php).

php artisan db:backup --database=otherdatabaseconnection

Choose a specific filename other than the default (default is 'Y-m-d_H-i-s' ). Note, do not include the file extension .sql, we will do that for you

php artisan db:backup --filename=my_project_backup

Upload the backup to S3

php artisan db:backup --s3-bucket=whatever --s3-path=/this/is/optional/

Cleanup file when we're done

php artisan db:backup --s3-bucket=whatever --s3-path=/this/is/optional/ --cleanup

Native PHP

<?php

require '../vendor/autoload.php';

// dump the database to backup/test.sql
$shellProcessor = new McCool\DatabaseBackup\Processors\ShellProcessor(new Symfony\Component\Process\Process(''));
$dumper = new McCool\DatabaseBackup\Dumpers\MysqlDumper($shellProcessor, 'localhost', 3306, 'username', 'password', 'test_db', 'backup/test.sql');

$backup = new McCool\DatabaseBackup\BackupProcedure($dumper);
$backup->backup();

// dump the database to backup/test.sql and gzip it
$shellProcessor = new McCool\DatabaseBackup\Processors\ShellProcessor(new Symfony\Component\Process\Process(''));
$dumper   = new McCool\DatabaseBackup\Dumpers\MysqlDumper($shellProcessor, 'localhost', 3306, 'username', 'password', 'test_db', 'backup/test.sql');
$archiver = new McCool\DatabaseBackup\Archivers\GzipArchiver($shellProcessor);

$backup = new McCool\DatabaseBackup\BackupProcedure($dumper);
$backup->setArchiver($archiver);

$backup->backup();

// dump the database to backup/test.sql, gzip it, upload it to S3, and clean up after ourselves
$shellProcessor = new McCool\DatabaseBackup\Processors\ShellProcessor(new Symfony\Component\Process\Process(''));
$dumper   = new McCool\DatabaseBackup\Dumpers\MysqlDumper($shellProcessor, 'localhost', 3306, 'username', 'password', 'test_db', 'backup/test.sql');
$archiver = new McCool\DatabaseBackup\Archivers\GzipArchiver($shellProcessor);
$storer   = new McCool\DatabaseBackup\Storers\S3Storer($awsKey, $awsSecret, 'us-east-1', $bucket, $s3Path);

$backup = new McCool\DatabaseBackup\BackupProcedure($dumper);
$backup->setArchiver($archiver);
$backup->setStorer($storer);

$backup->backup();
$backup->cleanup();

License

MIT

More Repositories

1

PHPStorm-SpacePeacock

An attempt at a decent looking PHPStorm setup.
Shell
312
star
2

vagrant-chef

My Chef cookbook collection along with some example Vagrantfiles
Ruby
111
star
3

laravel-form-base-model

A base model for forms.
PHP
97
star
4

tetris

PHP
32
star
5

laravel-closure-compiler

Closure-compiler bundle for Laravel.
PHP
21
star
6

laravel-eloquent-base-model

An Eloquent base model for Laravel.
PHP
15
star
7

tdd-kata

This repository is a PHP-based starter-kit for TDD Kata.
PHP
15
star
8

laravel-vanilla-integration

A Vanilla Forums Integration Bundle for Laravel Applications
PHP
15
star
9

avoiding-unified-data-models

This is the application built for the talk Avoiding Unified Data Models.
PHP
13
star
10

laravel-presentable

Presenter classes for Laravel
PHP
11
star
11

using-doctrine

Simple Doctrine Examples
PHP
10
star
12

php-telegram-pro

PHP
8
star
13

transaction-processing-example

Slammed together PHP code to serve as an example for conversation.
PHP
8
star
14

scala-event-sourcing

a hyper-minimalistic event-sourcing example
Scala
5
star
15

equipment-rental

an exercise in modeling
PHP
3
star
16

dotfiles-old

Shell
3
star
17

Conspicuous-Molyjam2013

A game created for Molyjam 2013 over two days by a team of four.
Haxe
3
star
18

shit-talk

A bare-bones project to bring google's speech-to-text to my desktop.
Ruby
3
star
19

laravel-slugs

An automated slug system for Laravel 4.
PHP
3
star
20

minimal-php-postmark-sdk

A minimal PHP Postmark SDK that enables you to send single and batched email through the PostmarkApp.com service.
PHP
2
star
21

modeling-kata-november-tic-tac-toe

PHP
2
star
22

old-lio

the old nextversion used to learn about some patterns (eventually dumped)
PHP
2
star
23

elastic-bash

I just don't know why anyone would make an ElasticSearch API with BASH.
Shell
2
star
24

event-sourcery-course-order-fulfillment-example

CSS
2
star
25

Component-Entity-Framework

C#
2
star
26

BraveTranslatorChromeExtension

A quick way to translate full pages in Brave / Chromium. Click the icon or Ctrl + Shift + 2.
JavaScript
1
star
27

game-prototyping-language

1
star