This Python script synchronizes a local directory to a remote WebDAV server.
Local files are always the reference (one‑way sync).
It uses a local state file (.webdav_sync_state.json) with SHA256 hashes to reliably detect changes, bypassing WebDAV's lack of checksum support.
rich) --nodelete) Save the script as rsync-webdav.py and make it executable:
chmod +x rsync-webdav.py
pip install webdavclient3
webdavclient3 – WebDAV operations Before synchronizing, you must create a configuration file.
Run:
./rsync-webdav.py create [options...]
You will be prompted for your WebDAV password.
The configuration is saved to ~/.config/webdav_sync_<NAME>.conf (plain text; use --password on the command line only if you understand the security implications).
<NAME> is the name of the configuration. It is determined from the name of the script at launching time. For example, if you rename the script rsync-my_config.py, then the <NAME> becomes my_config. On Unix systems, we recommend to create symbolic links to the original python script but with the expected name for the link.
Additional create options:
| Option | Description |
|---|---|
--url |
WebDAV server URL, e.g., https://myhost.mydomain.com/path/to/files) |
--user |
WebDAV username (default: current system user) |
--source |
Local source directory (default: ./) |
--excludes |
Space‑separated list of exclusion patterns, e.g., conf db lists |
Example with custom excludes:
./rsync-my_config.py create --source /home/user/data --excludes tmp cache '*.log'
.webdav_sync_state.json. --nodelete not given) – removes remote files whose local counterparts no longer exist. ./rsync-webdav.py sync
This will upload all changed/new files to the remote root (as defined in the configuration).
./rsync-webdav.py sync --dry-run -v
./rsync-webdav.py sync --nodelete
./rsync-webdav.py sync --excludes tmp '*.pyc'
Exclusion patterns support simple wildcards (*) and directory names.
Examples:
tmp – excludes any file/directory named tmp anywhere*.pyc – excludes all .pyc filesconf/* – excludes everything inside conf/generate_template_archives.py – excludes that specific fileThe state file .webdav_sync_state.json is automatically excluded.