captiolabs/backup-manager

A CLI tool to create and restore backups.

1.0.x-dev 2019-03-08 13:21 UTC

README

A CLI tool to create and restore local and off-site backups. Currently supports backing up files and MySQL databases.

Description

The Backup Manager currently support local and remote file and MySQL backups. The supported remote storage options are SFTP and WebDAV.

Requirements

  • PHP 7.2+
  • tar (available in $PATH)
  • gpg (available in $PATH)
  • mysqldump (available in $PATH)

Installation

  1. Run composer global require captiolabs/backup-manager.
  2. Make sure that your global Composer vendor directory is in your $PATH. If this is not the case run echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bash_profile.
  3. Reload your .bash_profile file by running source ~/.bash_profile
  4. Run backup-manager to start the application.

Configuration

The application is configured through a configuration file in the YAML format located at $HOME/.backup.yaml.

Example configuration ($HOME/.backup.yaml):

file:
  general:
    target:
      - /var/www
      - /var/log
    backup_name: backup_file # first part of the archive name
    backup_date: Y_m_d_H_i_s # second part of the archive name, supports any format accepted by date()
    timeout: 600
  encryption:
    password: password # used for GPG encryption
  local_storage:
    destination: /var/backup-manager/backup/file # local backup destination
    restore_location: /var/backup-manager/restore/file # used as default restore location, can be overwritten during restore
    retention: 90 # retention in days
  remote_storage:
    destination: /var/backup-manager/backup/file # remote backup destination
    retention: 90 # retention in days

mysql:
  general:
    backup_name: backup_mysql # first part of the archive name
    backup_date: Y_m_d_H_i_s # second part of the archive name, supports any format accepted by date()
    host: host
    port: 3306
    username: backup
    password: password
    temporary_location: /tmp/backup-manager/mysql # temporary database dump location, is deleted after the MySQL backup job finishes 
    timeout: 600
  encryption:
    password: password # used for GPG encryption
  local_storage:
    destination: /var/backup-manager/backup/mysql # local backup destination
    restore_location: /var/backup-manager/restore/mysql # used as default restore location, can be overwritten during restore
    retention: 90 # retention in days
  remote_storage:
    destination: /var/backup-manager/backup/mysql # remote backup destination
    retention: 90 # retention in days

remote_storage:
  type: webdav
  host: https://webdav.example.com/remote.php/webdav/
  username: username
  password: password

Remote storage

Providing a remote storage adapter is optional. When no remote storage adapter is configured only local backups are executed.

Supported remote storage configurations:

SFTP

remote_storage:
  type: sftp
  host: host
  port: 22
  username: username
  password: password # when providing a key file providing a password is unneeded 
  private_key: /home/user/.ssh/id_rsa # when providing a password providing a key file is unneeded 
  timeout: 600

WebDAV

remote_storage:
  type: webdav
  host: https://webdav.example.com/remote.php/webdav/
  username: username
  password: password

IMPORTANT: currently only one remote storage option can be defined!

Usage

General

  • List available commands: backup-manager list

Backup

  • Start file backup: backup-manager backup:file
  • Start MySQL backup: backup-manager backup:mysql

List

  • List local file backups: backup-manager backup:list file local
  • List remote file backups: backup-manager backup:list file remote
  • List local MySQL backups: backup-manager backup:list mysql local
  • List remote MySQL backups: backup-manager backup:list mysql remote

Restore

  • Restore local file backups: backup-manager backup:restore file
  • Restore local MySQL backups: backup-manager backup:restore mysql