Extensible backup automation tool using playbooks.
The project currently only supports the restic backend.
- See
pyproject.tomlfor the dependencies of this project - Install the backend you are planning to use:
- For
resticplaybooks, please install from https://restic.net
- For
- 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)
Please run the following command for usage information:
$ backup-automation --helpPlaybooks 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 playbooks are playbooks with the type field set to restic.
These playbooks must have the following fields: repositories and steps.
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-interactionswitch is active, the program will fail if it needs to ask for the password. - Plain text in the playbook
For this add thepasswordfield to your repository object with the password:"password": "my_plaintext_password" - Via environment variables
For this add thepasswordfield 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 repositoryRESTIC_FROM_PASSWORD— password for the source repository (only for the copy step)
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.
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 idsource_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.
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 idtarget_repository: Reference to the target repository via the repository id
{
"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"
}
]
}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.
See LICENSE file.