{"id":14972116,"url":"https://github.com/coderatio/simple-backup","last_synced_at":"2025-06-11T15:12:44.918Z","repository":{"id":56261060,"uuid":"178592103","full_name":"coderatio/simple-backup","owner":"coderatio","description":"A simple mysql database backup library for php.","archived":false,"fork":false,"pushed_at":"2024-09-27T06:35:33.000Z","size":684,"stargazers_count":58,"open_issues_count":1,"forks_count":13,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-15T14:14:29.554Z","etag":null,"topics":["backup","mysql-database","tables-mentioned"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coderatio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-30T17:46:45.000Z","updated_at":"2024-10-16T10:59:27.000Z","dependencies_parsed_at":"2024-06-21T12:58:02.840Z","dependency_job_id":"224656c6-2e73-40b5-9e3b-ac7b76f747ec","html_url":"https://github.com/coderatio/simple-backup","commit_stats":{"total_commits":29,"total_committers":6,"mean_commits":4.833333333333333,"dds":0.4482758620689655,"last_synced_commit":"e31b7b5fdd66b5432bf951d339c46f3b03ddf5a7"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderatio%2Fsimple-backup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderatio%2Fsimple-backup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderatio%2Fsimple-backup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderatio%2Fsimple-backup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderatio","download_url":"https://codeload.github.com/coderatio/simple-backup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249085429,"owners_count":21210267,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backup","mysql-database","tables-mentioned"],"created_at":"2024-09-24T13:46:24.702Z","updated_at":"2025-04-15T14:14:35.149Z","avatar_url":"https://github.com/coderatio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple-backup\n\u003cimg src=\"/_docs/store_export.PNG\"/\u003e\u003cbr/\u003e\nA 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. \n\nThe library also allows you import or restore a database without stress. Follow the instructions below to get started.\n\n## Installation\nOpen your terminal or command prompt and type the below command:\n```vim\ncomposer require coderatio/simple-backup\n```\n## New in version 1.0.1\n1. You can now chain static `::start()` on `SimpleBackup class. \n2. This version includes fluent chaining of database settings.\n3. Added `-\u003eincludeOnly(array $tables)` which allows you to export data for only tables mentioned in `$tables` variable.\n4. Added `-\u003eexcludeOnly(array $tables)` which removes the inclussion of tables mentioned in `$tables` variable during export.\n\n#### (v1.0.1) Exporting specific tables only\n```php\n  SimpleBackup::start()\n    -\u003esetDbName('db_name')\n    -\u003esetDbUser('db_username')\n    -\u003esetDbPassword('db_password')\n    -\u003eincludeOnly(['carts', 'houses', 'categories'])\n    -\u003ethen()-\u003estoreAfterExportTo('backups')\n    -\u003ethen()-\u003egetResponse();\n```\n\n#### (v1.0.1) Excluding specific tables only\n```php\n  SimpleBackup::start()\n    -\u003esetDbName('db_name')\n    -\u003esetDbUser('db_username')\n    -\u003esetDbPassword('db_password')\n    -\u003eexcludeOnly(['users', 'posts'])\n    -\u003ethen()-\u003estoreAfterExportTo('backups')\n    -\u003ethen()-\u003egetResponse();\n```\n\n---\n\n## Exporting\nThe export can be done in two ways.\n1. Store in a directory\n2. Download to your machine\n\n#### 1-- Store in a directory\nTo store the export in a directory, do this:\n```php\nrequire 'vendor/autoload.php';\n\nuse Coderatio\\SimpleBackup\\SimpleBackup;\n\n// Set the database to backup\n$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])\n  -\u003estoreAfterExportTo('pathtostore', 'file_name (optional)');\n```\nTo get the stored file name, you can echo it out like this:\n```php\necho $simpleBackup-\u003egetExportedName();\n```\nYou can also get the reponse by doing this:\n```php\n/**\n* @return object\n**/\nvar_dump($simpleBackup-\u003egetResponse());\n```\n\n#### 2-- Download\nTo download the export to your machine, do this:\n```php\nrequire 'vendor/autoload.php';\n\nuse Coderatio\\SimpleBackup\\SimpleBackup;\n\n// Set the database to backup\n$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])\n  -\u003edownloadAfterExport($file_name (optional));\n```\nIf $file_name isn't provided, a random name will be generated for the download.\n\n## Adding where clauses to tables\nTo add where clauses as you would do on SQL, you can do this before exporting:\n\n\u003cb\u003eNote:\u003c/b\u003e `$tables` variable must be an associative array e.g\n```php\n$tables = [\n  'users' =\u003e 'is_active = true'\n];\n```\n\n```php\n$simpleBackup-\u003esetTableConditions(array $tables);\n```\n\n## Setting rows limit on tables\nTo limit how many rows to be included in your backup for a table, do this before exporting:\n\n\u003cb\u003eNote:\u003c/b\u003e Just like adding where clauses, the `$tables` variable here must be an associative array. e.g\n```php\n$tables = [\n  'users' =\u003e 50,\n  'posts' =\u003e 50\n]\n```\n```php\n$simpleBackup-\u003esetTableLimitsOn(array $tables);\n```\n\n\n## Importing\nThis package makes importing or restoring your mysql database easy. To import your database, do this:\n```php\nrequire 'vendor/autoload.php';\n\nuse Coderatio\\SimpleBackup\\SimpleBackup;\n\n// Set the database to backup\n$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host (optional)']])\n    -\u003eimportFrom('pathtosql_file or sql_contents');\n\n/**\n* You can then dump the response like this. \n*\n* @return object\n**/\nvar_dump($simpleBackup-\u003egetResponse());\n```\n\u003cb\u003eNote:\u003c/b\u003e 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);`.\n\n## Todo\n1. Add a scheduler method to use with cron\n2. Store backup in Dropbox, Google Drive.\n3. Send backup to emails\n\n## Contribution\nTo contribute to this project, send a pull request or find me on \u003ca href=\"https://twitter.com/josiahoyahaya\" target=\"_blank\"\u003eTwitter\u003c/a\u003e.\n\n## License\nThis project is licenced with the MIT license. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderatio%2Fsimple-backup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderatio%2Fsimple-backup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderatio%2Fsimple-backup/lists"}