Skip to content

KGergo88/BackupAutomation

Repository files navigation

Backup Automation

Extensible backup automation tool using playbooks.

The project currently only supports the restic backend.

Requirements

  • See pyproject.toml for the dependencies of this project
  • Install the backend you are planning to use:

Installation

  • Clone the repository and install the package
$ git clone https://github.com/KGergo88/BackupAutomation.git
$ cd BackupAutomation
$ python -m pip install -e .

(The -e switch is only needed for development work)

Usage

Please run the following command for usage information:

$ backup-automation --help

Playbook format

Playbooks are JSON files. The repository contains example playbooks in the playbooks directory.

Playbooks must have a type field. This field defines the backend for the playbook. Possible values are: restic.

Example:

{
    "type": "restic",
}

Restic playbook format

Restic playbooks are playbooks with the type field set to restic.

These playbooks must have the following fields: repositories and steps.

Repositories

repositories list the restic repositories the playbook uses. These can be referenced via their id fields. If the id field is missing the uri will be used to generate an id value. For example this repository will have the implicit id Documents:

{ "uri": "C:\\ResticBackups\\Documents" }

Passwords of the repositories can be provided in the following ways:

  • During runtime in the terminal
    If no passwords are provided in the playbook, the program will ask for them. If the --no-interaction switch is active, the program will fail if it needs to ask for the password.
  • Plain text in the playbook
    For this add the password field to your repository object with the password: "password": "my_plaintext_password"
  • Via environment variables
    For this add the password field to your repository object that defines the name of the environment variable that stores the password: "password": "env:MY_RESTIC_PASSWORD_ENV_VAR"

The program will pass the passwords to the restic backend via temporarily setting environment variables:

  • RESTIC_PASSWORD — password for the target repository
  • RESTIC_FROM_PASSWORD — password for the source repository (only for the copy step)

Steps

steps are the sequence of actions the playbook will do upon execution. Every step has to have a command field. Possible values are: backup, copy. These represent their matching restic commands: restic backup and restic copy.

Backup

With the backup step a path can be backed up to a repository. The backup step needs to have the following fields:

  • repository: This is a reference to a repository via the repository id
  • source_path: The path that needs to be backed up to the repository

Optionally the tags field can be provided with a list of tags that needs to be applied to the new snapshot.

Copy

With the copy step snapshots can be copied between repositories. The copy step needs to have the following fields:

  • source_repository: Reference to the soruce repository via the repository id
  • target_repository: Reference to the target repository via the repository id

Simple example

{
	"type": "restic",
	"repositories": [
		{
            "id": "PC_Documents",
            "uri": "F:\\ResticBackups\\Documents"
        },
        {
            "id": "Raspberry_Documents",
            "uri": "sftp:johndoe@johndoe-raspberry:/media/johndoe/ExternalHdd/ResticBackups/Documents"
        }
	],
	"steps": [
		{
			"command": "backup",
			"repository": "Documents",
			"source_path": "D:\\Documents",
			"tags": ["RegularBackup"]
		},
        {
            "command": "copy",
            "source_repository": "PC_Documents",
            "target_repository": "Raspberry_Documents"
        }
	]
}

Contributing

Contributions and issues are welcome. Open an issue or a pull request on GitHub describing the change. When contributing, prefer small, focused changes and include tests where practical.

License

See LICENSE file.

About

Extensible backup automation tool using playbooks

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages