Looking for Magento 1.x support? Head over to magedbm.
magedbm2 is a database backup manager for Magento 2.
It was written with developers in mind and provides commands for:
- Creating sanitised (or unsanitised) Magento 2 production database backups and uploading them to Amazon S3
- Downloading and importing existing backups to development or staging environments
magedbm2 is compatible with PHP 7.0+ and requires exec
and passthru
functions to create and import database backups.
Run the following commands to install the latest version of magedbm2
globally:
curl -LO https://s3.eu-west-2.amazonaws.com/magedbm2-releases/magedbm2.phar
mv magedbm2.phar /usr/local/bin/magedbm2
chmod +x /usr/local/bin/magedbm2
magedbm2 uses Amazon S3 to store database backups. To use it you will need to create a bucket on S3 and a user read and write access to that bucket. Note down your:
- AWS Access Key ID
- AWS Secret Access Key
- S3 region where your bucket is hosted
- The bucket name
These details will need to be specified with option flags to most magedbm2 commands.
While the ability to specify the credentials as command line options is useful in automated scenarios, for personal everyday usage magedbm2 can be configured to remember your credentials by running:
magedbm2 configure [--access-key="..."] [--secret-key="..."] [--region="..."] [--bucket="..."] [-n]
By default, the configure command will interactively prompt you for each of the configuration details. Alternatively, you can run it in a non-interactive mode with the -n
option and specify the credentials you want to save by using the --access-key
, --secret-key
, --region
or --bucket
options.
The configuration is saved in a YAML file, usually located in ~/.magedbm2/config.yml
.
magedbm2 put [--strip="..."] [--clean=NUM|--no-clean] <project>
The put command will create a database backup from a Magento 2 installation at the current working directory (or the directory specified with --root-dir
) and upload it to S3.
By default, the command uses n98-magerun2 for database operations and creates backups with all customer data stripped out (the @development
strip setting to the n98-magerun2 db:dump
command). However, you can customise what data gets stripped, if any, using the --strip
option.
The put command also automatically cleans up old database backups once a new one has been uploaded, keeping only the 5 most recent backup files. You can customise the number of retained backups with the --clean
option, or disable it completely with --no-clean
.
magedbm2 ls [<project>]
The ls command will show the backup files available for import in S3. If called without a project name, it will show the available projects instead.
magedbm2 get [--download-only] [--force] get <project> [<file>]
Use the get command to download a backup file from S3 and import it to a Magento 2 installation at the current working directory (or the directory specified with --root-dir
).
By default, the get command will choose the latest backup file available for the given project. You can import specific backup files by providing the name of the file after the project name.
To download the backup file without importing it, use the --download-only
option. The file will be downloaded to the current working directory.
magedbm2 rm <project> <file>
The rm command allows you to delete specific backup files from S3.
While there is no formal contribution process, feel free to contribute by:
- Creating issues, bug reports or feature requests on Github
- Submitting pull requests for improvements
Pull requests should be submitted to the develop
branch to be included in the next release.
Developing magedbm2 requires:
- PHP 7.0+
- Phing
To install development dependencies for magedbm2, run:
phing install
magedbm2 follows PSR-2 for code style and a set of rules from phpmd to check for code problems.
You should run the following to check for any potential issues with the code before committing it:
phing lint
magedbm2 is tested with PHPUnit. 100% code coverage is not required, but all significant parts should have unit tests.
Make sure that the full suite of tests passes before committing changes by running:
phing test
You can build the magedbm2 phar archive with Box by running:
phing build
To release a new version of magedbm2:
-
Build the phar archive
-
Upload
magedbm2.phar
andmagedbm2-<version>.phar
to the magedbm2-releases S3 bucket -
Update the
manifest.json
file with the new version information and upload a copy of the file to the S3 bucketTo calculate the sha1 checksum of the phar archive, run:
sha1sum -a 1 magedbm2.phar
-
Create a release on Github