Backap is a MySQL database backup manager written in PHP that can be bundled into a PHAR file. Backap aims to simply the process of dumping, restoring and syncing MySQL databases using simple CLI commands.
You can use Backap in one of three ways:
You may download a ready-to-use version of Backap as a Phar:
$ curl -LSs https://tecactus.github.io/backap/installer.php | phpThe command will check your PHP settings, warn you of any issues, and the download it to the current directory. From there, you may place it anywhere that will make it easier for you to access (such as /usr/local/bin) and chmod it to 755. You can even rename it to just backap to avoid having to type the .phar extension every time.
$ backap --versionWhenever a new version of the application is released, you can simply run the update command to get the latest version:
$ backap updateThis is probably the best way when you have other tools like phpunit and other tools installed in this way:
$ composer global require tecactus/backap --prefer-sourceYou may also install Backap as a dependency for your Composer managed project:
$ composer require --dev tecactus/backapor
{
"require-dev": {
"tecactus/backap": "~1.0"
}
}Once you have installed the application, you can run the help command to get detailed information about all of the available commands. This should be your go-to place for information about how to use Backap.
$ backap helpthe init command creates a yaml configuration file called .backap.yaml into the current directory.
$ backap initThe .backap.yaml file structure is as follows:
In this attribute you can define the path where all the backup files generated with Backap will be stored.
This path MUST be ABOSULTE if is defined.
backap_storage_path: /absolute/path/to/backups/folderIf any path is defined or if you omit this attribute, Backap will create a storage/database folder into the current directory.
In this attribute you can define the path where mysqldump is located.
This path MUST be ABOSULTE if is defined.
mysqldump_path: /path/to/mysqldumpIf any path is defined or if you omit this attribute, Backap will try to call the globally reference to mysqldump.
In this attribute you can define the path where mysql is located.
This path MUST be ABOSULTE if is defined.
mysql_path: /path/to/mysqlIf any path is defined or if you omit this attribute, Backap will try to call the globally reference to mysql.
In this attribute you can define an specific timezone, this to know when the backup files were generated.
This timezone MUST have a VALID name.
For example:
timezone: America/LimaIf any timezone is defined or if you omit this attribute, Backap will use UTC.
Backap generates .sql files by default, you can tell Backap to compress the generated backup file enabling compression then Backap will generate .sql.gz files.
This value MUST be BOOLEAN if is defined.
enable_compression: trueIf any value is defined or if you omit this attribute, Backap sets compression as false by default.
Backap needs to know which of your database connections will dump or restore, that's why you have to define a default connection to work on when you do not explicits define one.
The connection name MUST be DECLARED as an element on the connections array attribute.
default_connection: myconnectionBackap can handle multiple database connections at the same time but first you have to define each one and asing them a diferent name.
Each connection MUST have *HOSTNAME, DATABASE and USERNAME * declared attribtues. PORT and PASSWORD are optional.
For example:
connections:
myconnection:
hostname: 192.168.1.27
port: 3306
database: important_db
username: userdb
password: supersecretpasswordIn the example we defined a connection named myconnection.
Of course you can define many as you want:
connections:
...
myconnection:
hostname: 192.168.1.27
port: 3306
database: important_db
username: userdb
...
otherconnection:
hostname: 177.200.100.9
port: 3306
database: other_db
username: admindb
password: supersecretpassword
...Backap allows you to sync your backup files with cloud providers as Dropbox.
To enable this feature you must declare and array atribute called cloud and inside them declare, with a unique name, each of the cloud adapters, as an array too, that will be available to sync.
For example:
cloud:
adapaterone:
...
adapatertwo:
...Each provider requires diferent parameters thats why every adapter required diferent attributes but all of them MUST have an ATTRIBUTE called provider.
For example:
cloud:
adapaterone:
provider: dropbox
...To declare a Dropbox adapter you must define the following attributes:
- provider as dropbox
- access_token generated on Dropbox for Developers
- app_secret generated on Dropbox for Developers
- path will be the path inside your Dropbox
For example:
cloud:
dropbox:
provider: dropbox
access_token: your_access_token
app_secret: your_secret
path: /path/on/your/dropboxThe mysql:dump command dumps the database for the default_connection .
$ backap mysql:dumpYou can explicit define one or more connections to be dumped
$ backap mysql:dump --conection myconnection --connection otherconnetionor
$ backap mysql:dump -c myconnection -c otherconnectionDisable file compression regardless if is enabled in .backap.yaml file. This option will be always overwrited by --compress option.
$ backap mysql:dump --no-compressEnable file compression regardless if is disabled in .backap.yaml file. This option will always overwrite --no-compress option.
$ backap mysql:dump --compressYou can sync dump files with one or more cloud provider at the moment the dump file is generated. This option will be always overwrited by --sync-all option.
$ backap mysql:dump --sync dropboxone --sync dropboxtwoor
$ backap mysql:dump -s dropboxone -s dropboxtwoAlso you can sync dump files with all the defined cloud provider at the same time at the moment the dump file is generated. This option will always overwrite --sync option.
$ backap mysql:dump --sync-allor
$ backap mysql:dump -SThe mysql:restore command restores the default_connection database from a backup file.
$ backap mysql:restoreThe mysql:restore command displays a list of all the backup files available only for the connection's database. Latest backup file is selected as default.
Then Backap ask for your confirmation to proceed with the database restoration.
You can explicit define the connection name to be restored
$ backap mysql:restore --conection otherconnetionor
$ backap mysql:restore -c otherconnectionYou can explicit define the backup file name to be restored
$ backap mysql:restore --filename mybackupfile.sqlor
$ backap mysql:restore -f mybackupfile.sqlThe mysql:restore command by default displays a list of all the backup files available only for the defined connection's database but you can use the --all-backup-files option to return a list of all backup file generated by Backap. Latest backup file is selected as default.
$ backap mysql:restore --all-backup-filesor
$ backap mysql:restore -A
Explicit restore the latest backup file for the connection's database.
$ backap mysql:restore --restore-latest-backup or
$ backap mysql:restore -LThe mysql:restore command always ask for your confirmation to proceed but you can confirm it without seeing the confirmation prompt using the --yes option.
$ backap mysql:restore --yesor
$ backap mysql:restore -yDisplay a list of cloud providers where to retrieve backup files.
$ backap mysql:restore --from-cloudor
$ backap mysql:restore -CExplicit define the cloud provider where to retrieve backup files
$ backap mysql:restore --from-provider dropboxoneor
$ backap mysql:restore -p dropboxoneThe files command displays a table with detailed data about all the backup files stored on your backap_storage_path
$ backap filesDisplay a list of cloud providers where to retrieve backup files.
$ backap files --from-cloudor
$ backap files -CExplicit define the cloud provider where to retrieve backup files
$ backap files --from-provider dropboxoneor
$ backap files -p dropboxoneThe sync command allows you to synchronize backup files with cloud providers. Pull files from cloud or push file to remote storage providers.
By default the sync asks you to choose a provider from a list of current configured providers but you can explicit define a provider using the --provider option.
The push action will sync all your backup files stored locally to the remote selected provider.
$ backap sync pushor
$ backap sync push --provider dropboxoneor
$ backap sync push -p dropboxoneThe pull action will sync all your backup files stored on the selected provider to your local storage folder.
$ backap sync pullor
$ backap sync pull --provider dropboxoneor
$ backap sync pull -p dropboxone