borgbase / ansible-role-borgbackup

Ansible role to set up Borg and Borgmatic
MIT License
227 stars 99 forks source link

[docs] Options to init newly-created repo #13

Open m3nu opened 5 years ago

m3nu commented 5 years ago

Should there be an option to also init the repo?

jerryoman commented 5 years ago

Hello, How can I create a new repo? Can you add (or is there) an option so this role will create a repo at first run?

Running borgmatic for the first time will fail with 'repo does not exist' :-1:

But Anyway, thank you for sharing this nice project! :)

m3nu commented 5 years ago

This issue exists because we don't init repos for now. There are some chicken-egg issues going on, if you think it through.

jerryoman commented 5 years ago

Ok, thanks for your reply! :)

So as workaround: Do you recommend to run the init repo thing manually after the role?

  post_tasks:
  - shell: /usr/local/bin/borgmatic init --encryption repokey
m3nu commented 5 years ago

This role will also create a SSH key to use for BorgBase or your own server. Before you run the init command, you will want to authorize the repo with this key. Just something to keep in mind.

Alternatively, you can use the BorgBase API to set up the repo and add the key. In that case, you can do it all at the same time automatically. The module for this is already part of this repo. It just misses some docs and I didn't personally test it for this case.

marienfressinaud commented 4 years ago

It could be great at least to give instructions in the readme of what needs to be done before executing this role :)

m3nu commented 4 years ago

Agree that this should be mentioned. You can also do this within Ansible, using this module:

- name: Create new repository for server in EU with new SSH_key and quota
  borgbase:
    repository_name: "{{ inventory_hostname }}"
    token: "Your Borgbase API Token"
    new_ssh_key: True
    ssh_key: "{{ some_variable }}"
    append_only: True
    quota_enable: True
    quota: 1000 #in GB
    region: eu
    alertdays: 2
  delegate_to: localhost
- name: Create new repository without new key and no quota/alerting in US region
  borgbase:
    repository_name: "{{ inventory_hostname }}"
    token: "Your Borgbase API Token"
    new_ssh_key: False
    ssh_key: "ssh-ed25519 AAAAC3Nz......aLqRJw+dl/E+2BJ xxx@yyy"
    region: us
  delegate_to: localhost
p-rintz commented 3 years ago

I have this automated on my end. But before I create PR for this Id want to smooth out the edges for any kind of issues you saw earlier.

You (@m3nu ) said that you see chicken and egg issues with this.

What I do in my automation is I add the root public key we created to the remote server in the first step (after the borgbackup role has run). Afterwards I update the known_hosts file for all repositories that are configured (support for PR #41 is done already) and then run borgmatic init --encryption repokey-blake2 as a shell command.

Do you see issues with that?

sinux-l5d commented 2 years ago

Hi, is there any update on this?