Most of my projects are made up of three components:
- Web application that lives in a directory.
- Database supporting the web application.
- Git repository somewhere.
This was built to back up these scenarios offsite by pulling the resources from their hosts and backing them up in the proverbial here.
- Supports multiple projects being backed up.
- Maintain a single living backup or a dated snapshot.
- Clone a local or remote directory via
rsync - Checkout a git repository via
git. - MySQL Backup via
mysqldumpoptionally via SSH tunnel.
- PHP 8.1+
rsyncfor directory backup.gitfor repository backup.sshfor tunneled database backup.mysqldumpfor db backup if notsshtunneling to host with it.
Start a new backup project. This will create a JSON file named this so it is best to choose simple names as you're going to retype it a lot.
$ bhd new <project>$ bhd new example
Add a new local or remote directory to copy over here.
$ bhd dir <project> <dir>$ bhd dir example example.tld:/path/to/app
Add a new git repository to clone over here.
$ bhd repo <project> <repo-url>$ bhd repo example git@example.tld:/path/to/repo
Add a new database to back up over here.
$ bhd db <project> --db=... --tunnel=... --host=... --user=... --pass=...$ bhd db example --db=ExampleDB --tunnel=example.tld --user=exuser --pass=expass
And then to remove it from the config.
$ bhd db example --del --db=ExampleDB
Perform all the actions configured for this project.
$ bhd run example
Run all the projects which are due to be updated. This would be what you want to put in your crontab.
$ bhd autorun
How It Works
-
rsync -azq --deletemeaning quietly archive, compress the network, and delete files in the destination that have been removed from the source. On a snapshot that means nothing but on a living backup it means it is kept in sync with the source. -
git clone repo-urlthe clone the repo as it is now. -
git pull -C pathin future runs if single living backups mode. -
mysqldump ... > backup.sqldirectly connecting and exporting the DB. -
ssh tunnel-host "mysqldump ..." > backup.sqlif TunnelHost is set.
Note: The SSH tunnel currently has no auth config in this utility as it is expecting you have magic key entry configured from here to there.
$ git clone https://github.com/bobmagicii/bhd$ cd bhd$ composer install
$ git pull && composer install
$ bhdto list all commands.$ bhd help <cmd>to see details about one command.- Note: if not PATHed then you need to run
$ php bin/bhd.
-
Project files are stored in
data/projects. -
Backups are stored in
data/backupsunlessBackupRootis defined indata/bhd.json. -
The CLI commands provided such as
backupandproject.atlworking as shown require adding./vendor/binand./binto PATH.
- This is sitting on top of my entire web stack so add a little self hosted dashboard for management.