vanegmondgroep/backup-cli

An extendable command-line interface for backing up and restoring data using Restic.

v1.0.0 2023-05-23 14:21 UTC

This package is auto-updated.

Last update: 2024-12-23 18:34:20 UTC


README

An extendable command-line interface for backing up and restoring data using Restic.

Install

Before installing Backup CLI, please make sure your environment meets the minimum requirements:

Once you’ve verified the requirements, download and install Backup CLI with Composer.

# Install Backup CLI package
composer require vanegmondgroep/backup-cli

By default, commands are invoked using the vendor/bin/bcli script. However, instead of repeatedly typing vendor/bin/bcli to execute commands, you may wish to configure a shell alias that allows you to execute commands more easily:

alias bcli='[ -f bcli ] && sh bcli || sh vendor/bin/bcli'

To make sure this is always available, you may add this to your shell configuration file in your home directory, such as ~/.zshrc or ~/.bashrc, and then restart your shell.

Commands

# Backup a service
bcli backup <service>

# Display service snapshots
bcli snapshots <service>

# Restore a service
bcli restore <service> <snapshot-id>

# Display backup logs
bcli logs <service>

Configuration

Backup CLI loads environment variables from a .env file within the current working directory. The following variables are available:

** This defines a service path you would like to back up (e.g. MYSQL_BACKUP_PATH).

Hooks

Backup CLI calls scripts (hooks) before and after a backup or restore. This allows you to perform an action, such as exporting a database before a backup is made. The following hooks are available:

Logs

Logs are written to $BACKUP_LOGS_PATH/<service>.log.

Example

The example configuration shows how you can back up / restore a MySQL and Node-RED container.

Cronjobs

To schedule a backup, add the following line to your crontab:

# Run MySQL backup every day at 01:00
0 1 * * * cd <project-dir> && vendor/bin/bcli backup mysql

# Run Node-RED backup every day at 02:00
0 2 * * * cd <project-dir> && vendor/bin/bcli backup node-red