Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use none standart ssh port for connections and Fix bugs #1

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ borgbackup_server_group: "borgbackup"
borgbackup_server_home: "/srv/borgbackup"
borgbackup_server_pool: "{{ borgbackup_server_home }}/repos"

# if necessary, specify a password for the backup server in order to
# if necessary, specify a password for the backup server in order to
# add the client ssh key to the backup server's authorized keys
# borgbackup_server_password: "{{ vault_borgbackup_server_password }}"

Expand All @@ -34,6 +34,8 @@ borgbackup_passphrase: "{{ vault_borgbackup_passphrase }}"
## borg client configuration
##
borgbackup_client: False
# SSH server port
borgbackup_client_backup_server_port: 22

# Specify the SSH private key type to use. By default role will generate
# ED25519 keys if they are supported by the remote host, otherwise RSA keys
Expand All @@ -55,7 +57,7 @@ borgbackup_client_lastlog_dir: "/var/log/borg"
# max retry attempt on create/prune/check task failure. only one attempt if unset.
#borgbackup_task_retry: 3

# retry attempt wait time
# retry attempt wait time
#borgbackup_task_retry_wait: 30

# borgbackup jobs examples :
Expand Down Expand Up @@ -84,4 +86,4 @@ borgbackup_check_enabled: yes
# check_options: "--lock-wait 28800"
# day: "*"
# hour: 4
# minute: 0
# minute: 0
14 changes: 5 additions & 9 deletions tasks/borgbackup_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,17 @@

- name: add ssh-pubkey to backup server
vars:
ansible_become_pass: "{{ borgbackup_server_password | default(ansible_become_password) }}"
ansible_become_pass: "{{ borgbackup_server_password | default('') }}"
delegate_to: "{{ borgbackup_client_backup_server }}"
# Start the delegate from the ansible master to avoid distributing more keys
connection: local
authorized_key:
user: "{{ borgbackup_server_user }}"
key: "{{ borgbackup_client_ssh_pubkey_file.stdout }}"
key_options: 'command="cd {{ borgbackup_server_pool }}/{{ inventory_hostname }};borg serve --restrict-to-path {{ borgbackup_server_pool }}/{{ inventory_hostname }}",no-port-forwarding,no-X11-forwarding,no-pty,no-agent-forwarding,no-user-rc'

- name: create repo path for host
vars:
ansible_become_pass: "{{ borgbackup_server_password | default(ansible_become_password) }}"
ansible_become_pass: "{{ borgbackup_server_password | default('') }}"
delegate_to: "{{ borgbackup_client_backup_server }}"
# Start the delegate from the ansible master to avoid distributing more keys
connection: local
file:
path: "{{ borgbackup_server_pool }}/{{ inventory_hostname }}"
owner: "{{ borgbackup_server_user }}"
Expand All @@ -64,7 +60,7 @@
- name: check if the repositories already exist
command: "{{ borgbackup_binary }} list {{ borgbackup_server_user }}@{{ borgbackup_client_backup_server }}:{{ item.name }}"
environment:
- BORG_RSH: "ssh -o StrictHostKeyChecking=no -i {{ borgbackup_client_ssh_key_file }}"
- BORG_RSH: "ssh -o StrictHostKeyChecking=no -i {{ borgbackup_client_ssh_key_file }} -p {{ borgbackup_client_backup_server_port }}"
- BORG_PASSPHRASE: "{{ borgbackup_passphrase }}"
with_items: "{{ borgbackup_create_jobs }}"
register: list_repos
Expand All @@ -85,7 +81,7 @@
- name: initialize repositories
command: "{{ borgbackup_binary }} init --encryption {{ borgbackup_encryption_mode }} {{ borgbackup_server_user }}@{{ borgbackup_client_backup_server }}:{{ item.name }}"
environment:
- BORG_RSH: "ssh -o StrictHostKeyChecking=no -i {{ borgbackup_client_ssh_key_file }}"
- BORG_RSH: "ssh -o StrictHostKeyChecking=no -i {{ borgbackup_client_ssh_key_file }} -p {{ borgbackup_client_backup_server_port }}"
- BORG_PASSPHRASE: "{{ borgbackup_passphrase }}"
with_items: "{{ borgbackup_create_jobs }}"
register: borgbackup_initialize_result
Expand Down Expand Up @@ -193,4 +189,4 @@
args:
chdir: "{{ borgbackup_client_lastlog_dir }}"
creates: "{{ borgbackup_client_lastlog_dir }}/{{ item.name }}_{{ check_suffix_script_filename }}.lastlog"
with_items: "{{ borgbackup_check_jobs }}"
with_items: "{{ borgbackup_check_jobs }}"
2 changes: 1 addition & 1 deletion templates/check_job.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

export BORG_RSH="ssh -i {{ borgbackup_client_ssh_key_file }}"
export BORG_RSH="ssh -i {{ borgbackup_client_ssh_key_file }} -p {{ borgbackup_client_backup_server_port }}"
export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"

REPOSITORY={{ borgbackup_server_user }}@{{ borgbackup_client_backup_server_lanfreebackup | default(borgbackup_client_backup_server) }}:{{ item.name }}
Expand Down
6 changes: 3 additions & 3 deletions templates/create_job.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

export BORG_RSH="ssh -i {{ borgbackup_client_ssh_key_file }}"
export BORG_RSH="ssh -i {{ borgbackup_client_ssh_key_file }} -p {{ borgbackup_client_backup_server_port }}"
export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"

REPOSITORY={{ borgbackup_server_user }}@{{ borgbackup_client_backup_server_lanfreebackup | default(borgbackup_client_backup_server) }}:{{ item.name }}
Expand All @@ -19,6 +19,6 @@ while [ $retry -gt 0 ]; do
{% endfor %}
2>&1 | tee {{ borgbackup_client_lastlog_dir }}/{{ item.name }}_{{ create_suffix_script_filename }}.lastlog \
| /usr/bin/logger -t borgbackup_backup_{{ item.name }}_{{ borgbackup_client_backup_server }}
for i in ${PIPESTATUS[@]}; do let step_status+=$i ;done
if [ $step_status -eq 0 ]; then retry=0; else sleep {{ borgbackup_task_retry_wait | default(30) }}; let retry-=1; fi
for i in ${PIPESTATUS[@]}; do step_status+=$((step_status+i)) ;done
if [ $step_status -eq 0 ]; then retry=0; else sleep {{ borgbackup_task_retry_wait | default(30) }}; retry=$((retry-1)); step_status=0; fi
done
2 changes: 1 addition & 1 deletion templates/prune_job.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

export BORG_RSH="ssh -i {{ borgbackup_client_ssh_key_file }}"
export BORG_RSH="ssh -i {{ borgbackup_client_ssh_key_file }} -p {{ borgbackup_client_backup_server_port }}"
export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"

REPOSITORY={{ borgbackup_server_user }}@{{ borgbackup_client_backup_server_lanfreebackup | default(borgbackup_client_backup_server) }}:{{ item.name }}
Expand Down