0

I am trying to download backup files from my websites. I have structured my playbook the following:

  1. site_vars.yml holds my variables:
website_backup_download:
 - name: ftp://username:[email protected]/backups/mysite1backup.tgz
   path: mysites/backups/www
 - name: ftp://username:[email protected]/backups/mysite2backup.tgz
   path: mysites/backups/www
 - name: ftp://username:[email protected]/backups/mysite3backup.tgz
   path: mysites/backups/www
  1. Actual downloader playbook:
# Downloader

task:
  - name: Download backups from FTP's
    get_url:
      url: "{{ item.name }}"
      dest: "{{ item.path }}"
      mode: 0750
    no_log: false
    ignore_errors: True
    with_items:
      - "{{ website_backup_download }}"

This works actually very well, but the problem begins with large backup files, the task needs to be running until the backup file has been downloaded properly.

I can't repeat the task to complete the incompleted file or files. :)

Have tried another solution, this works also well for a single site, but can't use it for multiple downloads :(

- name: Download backups
  command: wget -c ftp://username:[email protected]/backups/mysite1backup.tgz
    args:
      chdir: "{{ down_path }}"
      warn: false
    register: task_result
    retries: 10
    delay: 1
    until: task_result.rc == 0
    ignore_errors: True

Thanks for your help.

4
  • Regarding "...the problem begins with large backup files...", can you specify in more detail what large means? Regarding "...the task needs to be running until the backup file has been downloaded properly...", can you provide more details? Isn't the task that doing? How long is the task running? After which time "...incompleted file or files..." were left? What happen at that stage? Was there a error message?
    – U880D
    Commented Nov 30, 2021 at 8:13
  • let's say, mysite1backup.tgz backup file is 750 MB, the other one was 50 MB, and the other is smaller than 50 MB. The task finishes with no problem, downloads all files in full but except one, mysite1backup.tgz is either 400 or 550 MB partially downloaded.
    – theadmin
    Commented Nov 30, 2021 at 8:29
  • How about the runtime? How long is the task running? After which time "...incompleted file or files..." were left? The get_url module has a parameter timeout. You could perform a short test with an increased value.
    – U880D
    Commented Nov 30, 2021 at 8:42
  • Did you took a look here: stackoverflow.com/questions/47955615/…
    – Kevin C
    Commented Nov 30, 2021 at 9:22

1 Answer 1

1

I have modified the task by adding the timeout parameter for runtime, additionally added the until parameter, waiting for download to be finished, and retry and delay parameters to retrying until it meths conditions.

This works for now :) Thanks to all of you.

# Downloader

task:
  - name: Download backups from FTP's
    get_url:
      url: "{{ item.name }}"
      dest: "{{ item.path }}"
      mode: 0750
      timeout: 1800
    retries: 10
    delay: 3
    register: result
    until: result is succeeded
    no_log: false
    ignore_errors: True
    with_items:
      - "{{ website_backup_download }}"

Not the answer you're looking for? Browse other questions tagged or ask your own question.