Zum Inhalt

rclone_download

Overview

The rclone_download module pulls files down from one or more external "storage box" accounts onto the NAS, using the rclone command-line tool as a subprocess. It's a generic ingestion utility for bringing externally-hosted source content (e.g. content delivered by a publisher via SFTP, or files parked in a cloud storage bucket) onto local storage (a preparatory step that runs before any harvesting module ever touches the resulting files, not a per-article pipeline module itself).

Unlike the article-level modules, this module has no concept of ISSNs, article DOIs, or the previous_module convention. Its only unit of work is a single storage box account, defined entirely in a JSON config file, one call to rclone per account, either copying or moving files from that account's remote location to a configured destination folder on the NAS.

Module ordering: rclone_download should run before the module that is meant to process the downloaded files (e.g. copernicus, which expects zip files to already be present on the non-backed-up NAS).

The module contains two primary Python files:

  1. flow.py
  2. tasks.py

flow.py

This file defines the main flow for storage-box downloads using the Prefect library, and uses prefect's get_run_logger (with log_prints=True). It reads the list of configured storage-box accounts and processes each one in turn, sequentially.

rclone_download()

  • Required Parameters:

  • name_of_storagebox_accounts_file (str): Name of the JSON file listing storage-box accounts to process. Default is "rclone_storagebox_accounts.json"

  • Context for Use:

  • This function is the main entry point. It resolves both the backed-up data root (data_root, used only to locate the accounts config file) and the non-backed-up data root (data_root_temp, used as the destination for downloaded files), reads the accounts list via read_config_file, and calls move_files_from_storagebox_to_nas once per account, sequentially.

  • Example Usage:

  • python rclone_download('rclone_storagebox_accounts.json')

  • Example Output:

  • INFO: Path to log file: /mnt/.../rclone_download/....log INFO: Overview over all storagebox users whose data will be downloaded to the nas: [{'rclone_name': 'example_name', 'rclone_command': 'copy', 'folder_on_wdm_nas': 'storagebox-test/example_acc_name'}] INFO: Downloading files for storagebox user: example_name INFO: Downloading to folder: /mnt/.../storagebox-test/example_acc_name INFO: The following is the command line output from Rclone: ... INFO: The following is debug information from Rclone: ...

tasks.py

This file contains the two task definitions used in the storage-box download flow: reading the accounts config file, and running the actual rclone subprocess call per account.

read_config_file()

  • Required Parameters:

  • nas_root (Path or str): The backed-up data root (used to locate the accounts config file)

  • name_of_storagebox_accounts_file (str): Name of the JSON config file to read

  • Context for Use:

  • A Prefect @task that reads the storage-box accounts config file from a fixed subfolder — <nas_root>/storagebox-test/<name_of_storagebox_accounts_file> — regardless of what nas_root itself points to. Returns the list under the storagebox_users key. Logs the full list of accounts that will be processed before returning.

  • Example Usage:

  • python storagebox_users = read_config_file(data_root, "rclone_storagebox_accounts.json")

  • Example Output:

  • python [ { "rclone_name": "example_name", "rclone_command": "copy", "folder_on_wdm_nas": "storagebox-test/example_acc_name" } ]

move_files_from_storagebox_to_nas()

  • Required Parameters:

  • storagebox_user (dict): One account entry from the accounts config file. (Expected keys: rclone_name, rclone_command ("copy" or "move"), ftp_subfolder_if_required, folder_on_wdm_nas)

  • nas_root (Path or str): The non-backed-up data root; the actual download destination is <nas_root>/<storagebox_user['folder_on_wdm_nas']>

  • Context for Use:

  • A Prefect @task (given a dynamic task_run_name that includes the storage-box user's name, so each account's run is individually identifiable in the Prefect UI) that shells out to the rclone CLI via subprocess.run. Two modes are supported:

    • "copy" — runs rclone --checksum copy <remote>:<subfolder> <destination> --log-level INFO. The --checksum flag verifies file integrity by content hash.
    • "move" — runs rclone move <remote>:<subfolder> <destination> --delete-empty-src-dirs --log-level INFO. Files are moved (not copied) from the remote, and any source directories left empty afterward are deleted.
  • Any other value for rclone_command is not executed.
  • On a successful copy or move, the captured stdout and stderr from the rclone process are logged via get_run_logger().

  • Example Usage:

  • python move_files_from_storagebox_to_nas( {"rclone_name": "example_name", "rclone_command": "copy", "ftp_subfolder_if_required": "", "folder_on_wdm_nas": "storagebox-test/example_acc_name"}, data_root_temp, )

  • Example Output:

  • No return value. Side effect: files copied/moved onto the NAS at <nas_root>/<folder_on_wdm_nas>, plus logged rclone command output.