Skip to main content

file sync tool

PyPI - Python Version PyPI Pepy Total Downloads PyPI - Downloads Scrutinizer Code Quality Build Status

Python script to synchronize files from an origin to a target system using rsync.

This tool is an addon of the db-sync-tool.

Example receiver

Installation

Prerequisite

The script needs python 3.5 or higher. It is necessary for some additional functionalities to have pip installed on your local machine.

pip

The library can be installed from PyPI:

$ pip3 install file-sync-tool-kmi

composer

The script is also available via packagist.org using composer:

$ composer require kmi/file-sync-tool

Additionally install the python requirements via the following pip command:

$ pip3 install -e vendor/kmi/file-sync-tool/

Configuration

You can configure the script with shell arguments or using a separate configuration file.

Configuration File

The config.json contains important information about the origin and the target system.

Example structure of config.json in receiver mode :

{
  "target": {},
  "origin": {
    "host": "ssh_host",
    "user": "ssh_user"
  },
  "files": {
    "config": [
      {
        "origin": "/var/www/html/files/",
        "target": "/var/www/html/files/",
        "exclude": [
          "*.log"
        ]
      }
    ]
  }
}

Documentation

Extend the config.json with a files section containing multiple transfer entries within the configentry. Therefore you have to specify the origin source path as well as the target destination path of the file sync. Additionally define the rsync excludes for this specific transfer.

In the config entry you can also define additional rsync options as a list overwriting the default options.

For further information see the documentation of the db-sync-tool.

Usage

Command line

Run the python script via command line.

Installed via pip:

$ file_sync_tool

Installed via composer:

$ python3 vendor/kmi/file-sync-tool/file_sync_tool

Shell arguments

usage: file_sync_tool [-h] [-f CONFIG_FILE] [-v] [-m] [-o HOST_FILE]
                      [-th TARGET_HOST] [-tu TARGET_USER]
                      [-tpw TARGET_PASSWORD] [-tk TARGET_KEY]
                      [-tpo TARGET_PORT] [-oh ORIGIN_HOST] [-ou ORIGIN_USER]
                      [-opw ORIGIN_PASSWORD] [-ok ORIGIN_KEY]
                      [-opo ORIGIN_PORT] [-fo FILES_ORIGIN] [-ft FILES_TARGET]
                      [-fe FILES_EXCLUDE] [-fop FILES_OPTION]

A tool for automatic file synchronization from and to host systems.

optional arguments:
  -h, --help            show this help message and exit
  -f CONFIG_FILE, --config-file CONFIG_FILE
                        Path to configuration file
  -v, --verbose         Enable extended console output
  -m, --mute            Mute console output
  -o HOST_FILE, --host-file HOST_FILE
                        Using an additional hosts file for merging hosts
                        information with the configuration file
  -th TARGET_HOST, --target-host TARGET_HOST
                        SSH host to target system
  -tu TARGET_USER, --target-user TARGET_USER
                        SSH user for target system
  -tpw TARGET_PASSWORD, --target-password TARGET_PASSWORD
                        SSH password for target system
  -tk TARGET_KEY, --target-key TARGET_KEY
                        File path to SSH key for target system
  -tpo TARGET_PORT, --target-port TARGET_PORT
                        SSH port for target system
  -oh ORIGIN_HOST, --origin-host ORIGIN_HOST
                        SSH host to origin system
  -ou ORIGIN_USER, --origin-user ORIGIN_USER
                        SSH user for origin system
  -opw ORIGIN_PASSWORD, --origin-password ORIGIN_PASSWORD
                        SSH password for origin system
  -ok ORIGIN_KEY, --origin-key ORIGIN_KEY
                        File path to SSH key for origin system
  -opo ORIGIN_PORT, --origin-port ORIGIN_PORT
                        SSH port for origin system
  -fo FILES_ORIGIN, --files-origin FILES_ORIGIN
                        File path for origin source of file sync
  -ft FILES_TARGET, --files-target FILES_TARGET
                        File path for target destination of file sync
  -fe FILES_EXCLUDE, --files-exclude FILES_EXCLUDE
                        Excludes for file sync
  -fop FILES_OPTION, --files-option FILES_OPTION
                        Additional rsync options

If you haven't declare a path to a SSH key, during the script execution you are requested to enter the SSH password for the given user in the shell argument or the config.json to enable a SSH connection for the remote system.

Import

You can import the python package and use them inside your project:

from file_sync_tool import sync

if __name__ == "__main__":
    sync.Sync(config={}, args*)

Release Guide

A detailed guide is available to release a new version. See here.

Tests

A docker container set up is available for testing purpose. See here.

Metadata

Release files for file-sync-tool-kmi 0.4.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for file-sync-tool-kmi 0.4.9
File Size Uploaded Provenance Actions
file_sync_tool_kmi-0.4.9.tar.gz 11.6 kB Without provenance Details for file_sync_tool_kmi-0.4.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for file-sync-tool-kmi 0.4.9
File Interpreter ABI Platform Actions
file_sync_tool_kmi-0.4.9-py3-none-any.whl Python 3 none any Details for file_sync_tool_kmi-0.4.9-py3-none-any.whl

Total release size: 23.7 kB

Release files / file_sync_tool_kmi-0.4.9.tar.gz

Download URL file_sync_tool_kmi-0.4.9.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
67a06d07da2a27d5b7bf4b8cb8a548031fe0b879fe0ecf043356c6543c09a50b
BLAKE2b-256 checksum
How to use checksums
ebdeb231e5f8a4cb16a9e8cfa72b4e5ab77e88c3be01390bd0eab6f8879f1c71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release files / file_sync_tool_kmi-0.4.9-py3-none-any.whl

Download URL file_sync_tool_kmi-0.4.9-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9e58de54e9ea5aa549a0dfeba3b447dd07b03ac3d8ec4554b5fab2c9738c6be
BLAKE2b-256 checksum
How to use checksums
3fdaef06d87f50e46ba2562f6d39d78490bc199dd49df27082a9737350968934
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Security for file-sync-tool-kmi 0.4.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page