====== XNAT data syncing ======
Scan data in XNAT can be mirrored using a local XNAT or copied using the REST API.
One way to use the API is using either python [[https://xnat.readthedocs.io/en/latest/|xnat]] or [[https://gitlab.com/radiology/infrastructure/xnatpy|xnatpy]] library.
For ''rsync'' from [[data:filesystem]] or ''fw download'' using [[:data:flywheel]] comparable scripts:.
* An example using ''import xnat'' from MC is on [[https://github.com/MingHsuanChiang/cron_mrproj_share/blob/main/mrproj.py|github]].
* Alternatively, a script to mirror the dcmtk storescp DICOM listener file and path pattern written to ''[[:data:filesystem|scan_data/]]'' can be found on [[https://github.com/NPACore/xnat-hpc/tree/main/misc/xnat_sync_raw.py]].
# write authentication information
echo '{"server": "https://xnat.mrrc.upmc.edu", "user": "MYUSER", "password": "MYPASSWORD"}' > mrrc-xnat.cfg
# using 'uv' from https://docs.astral.sh/uv/
PROJCODE=WPC-1234 RAWROOT=/tmp/sync/test DRYRUN=1 \
uv run --script https://raw.githubusercontent.com/NPACore/xnat-hpc/refs/heads/main/misc/xnat_sync_raw.py