All Projects → coderatio → simple-backup

coderatio / simple-backup

Licence: MIT License
A simple mysql database backup library for php.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to simple-backup

iceshelf
A simple tool to allow storage of signed, encrypted, incremental backups using Amazon's Glacier storage
Stars: ✭ 28 (-26.32%)
Mutual labels:  backup
paperback
Paper backup generator suitable for long-term storage.
Stars: ✭ 517 (+1260.53%)
Mutual labels:  backup
github-backup-docker
Docker wrapper for github-backup
Stars: ✭ 38 (+0%)
Mutual labels:  backup
radio
Redundant Array of Distributed Independent Objectstores in short RADIO performs synchronous mirroring, erasure coding across multiple object stores
Stars: ✭ 25 (-34.21%)
Mutual labels:  backup
trellis-backup-during-deploy
Backup WordPress database during Trellis deploys
Stars: ✭ 23 (-39.47%)
Mutual labels:  backup
docker base images
Vlad's Base Images for Docker
Stars: ✭ 61 (+60.53%)
Mutual labels:  backup
yii2-db-manager
Database Backup and Restore functionality
Stars: ✭ 96 (+152.63%)
Mutual labels:  backup
zzmysqldump
mysqldump every DB of your MySQL Server to its own, 7z-compressed file.
Stars: ✭ 47 (+23.68%)
Mutual labels:  backup
compose-dump
Dump and restore Docker Compose-projects
Stars: ✭ 14 (-63.16%)
Mutual labels:  backup
dijnet-bot
Az összes számlád még egy helyen :)
Stars: ✭ 17 (-55.26%)
Mutual labels:  backup
couchbackup
CouchDB backup and restore command-line utility.
Stars: ✭ 15 (-60.53%)
Mutual labels:  backup
ioBroker.backitup
Backitup enables the cyclical creation of backups of an IoBroker / Homematic installation
Stars: ✭ 43 (+13.16%)
Mutual labels:  backup
docker-backup-to-s3
Docker container that periodically backups files to Amazon S3 using s3cmd and cron
Stars: ✭ 124 (+226.32%)
Mutual labels:  backup
joplin-scripts
scripts for Joplin
Stars: ✭ 40 (+5.26%)
Mutual labels:  backup
BM
The Utility to Install Songs, Install Mods, Install/Update BMBF, Install HitSounds, download automatically made Playlists, get better support, switch between the modded and unmodded Version of Beat Saber, do full Backups and way more
Stars: ✭ 33 (-13.16%)
Mutual labels:  backup
face-attendence
Face Attendance (AWS rekognition)
Stars: ✭ 39 (+2.63%)
Mutual labels:  mysql-database
myhoard
MySQL Backup and Point-in-time Recovery service
Stars: ✭ 62 (+63.16%)
Mutual labels:  backup
my-learning-analytics
My Learning Analytics project
Stars: ✭ 28 (-26.32%)
Mutual labels:  mysql-database
doteur
Tool to automate the visualisation of SQL schemas from a SQL file
Stars: ✭ 80 (+110.53%)
Mutual labels:  mysql-database
abgleich
zfs sync tool
Stars: ✭ 22 (-42.11%)
Mutual labels:  backup

Simple-backup


A simple mysql database backup library for php. This library helps you backup your mysql database to a directory in your project or download it to your machine.

The library also allows you import or restore a database without stress. Follow the instructions below to get started.

Installation

Open your terminal or command prompt and type the below command:

composer require coderatio/simple-backup

New in version 1.0.1

  1. You can now chain static ::start() on `SimpleBackup class.
  2. This version includes fluent chaining of database settings.
  3. Added ->includeOnly(array $tables) which allows you to export data for only tables mentioned in $tables variable.
  4. Added ->excludeOnly(array $tables) which removes the inclussion of tables mentioned in $tables variable during export.

(v1.0.1) Exporting specific tables only

  SimpleBackup::start()
    ->setDbName('db_name')
    ->setDbUser('db_username')
    ->setDbPassword('db_password')
    ->includeOnly(['carts', 'houses', 'categories'])
    ->then()->storeAfterExportTo('backups')
    ->then()->getResponse();

(v1.0.1) Excluding specific tables only

  SimpleBackup::start()
    ->setDbName('db_name')
    ->setDbUser('db_username')
    ->setDbPassword('db_password')
    ->excludeOnly(['users', 'posts'])
    ->then()->storeAfterExportTo('backups')
    ->then()->getResponse();

Exporting

The export can be done in two ways.

  1. Store in a directory
  2. Download to your machine

1-- Store in a directory

To store the export in a directory, do this:

require 'vendor/autoload.php';

use Coderatio\SimpleBackup\SimpleBackup;

// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])
  ->storeAfterExportTo('pathtostore', 'file_name (optional)');

To get the stored file name, you can echo it out like this:

echo $simpleBackup->getExportedName();

You can also get the reponse by doing this:

/**
* @return object
**/
var_dump($simpleBackup->getResponse());

2-- Download

To download the export to your machine, do this:

require 'vendor/autoload.php';

use Coderatio\SimpleBackup\SimpleBackup;

// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])
  ->downloadAfterExport($file_name (optional));

If $file_name isn't provided, a random name will be generated for the download.

Adding where clauses to tables

To add where clauses as you would do on SQL, you can do this before exporting:

Note: $tables variable must be an associative array e.g

$tables = [
  'users' => 'is_active = true'
];
$simpleBackup->setTableConditions(array $tables);

Setting rows limit on tables

To limit how many rows to be included in your backup for a table, do this before exporting:

Note: Just like adding where clauses, the $tables variable here must be an associative array. e.g

$tables = [
  'users' => 50,
  'posts' => 50
]
$simpleBackup->setTableLimitsOn(array $tables);

Importing

This package makes importing or restoring your mysql database easy. To import your database, do this:

require 'vendor/autoload.php';

use Coderatio\SimpleBackup\SimpleBackup;

// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host (optional)']])
    ->importFrom('pathtosql_file or sql_contents');

/**
* You can then dump the response like this. 
*
* @return object
**/
var_dump($simpleBackup->getResponse());

Note: You can provide sql statements as the parameter. You may also overwrite the database configuration by passing it as second parameter to the importFrom(). e.g importFrom(pathtosql_file, array $db_config);.

Todo

  1. Add a scheduler method to use with cron
  2. Store backup in Dropbox, Google Drive.
  3. Send backup to emails

Contribution

To contribute to this project, send a pull request or find me on Twitter.

License

This project is licenced with the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].