Skip to main content

Repair incomplete or corrupt rosbag2 (sqlite3 .db3) bags by recovering the database and rebuilding metadata.yaml — no ROS 2 install required.

Project description

ros2bag-repairer

Repair incomplete or corrupt rosbag2 (sqlite3 .db3) bags — the kind a recorder leaves behind when it's killed mid-run. No ROS 2 installation required; it works directly on the .db3 with the Python standard library and the sqlite3 CLI.

What it fixes

Symptom What happened Repair
ros2 bag play can't open the bag recorder died before writing metadata.yaml rebuild metadata.yaml from the messages in the .db3
messages missing / bag truncated a <bag>_0.db3-wal was never checkpointed fold the WAL back into the database
"database disk image is malformed" the .db3 is partially corrupt salvage with sqlite .recover (falls back to .dump), backing up the original

metadata.yaml is fully derivable from the database: the topics table holds every topic's name/type/serialization/QoS, and the messages table holds the counts and timestamps. The tool recomputes all of it (version 5, sqlite3), which is exactly what makes a metadata-less bag playable again.

Install

pip install -e .          # from this directory
# or run without installing:
python -m ros2bag_repairer.cli <bag>   # with src/ on PYTHONPATH

Requires Python ≥ 3.8, PyYAML, and the sqlite3 command-line tool (only needed for the corrupt-database recovery path).

Use

# Repair in place (rebuilds metadata.yaml; backs up any db it has to recover):
ros2bag-repair /data/recordings/zed_20260621_225845

# Or a single .db3 file:
ros2bag-repair /data/recordings/zed_20260621_225845/zed_20260621_225845_0.db3

# Write the repaired bag elsewhere, leaving the original untouched:
ros2bag-repair <bag> --output ~/bag_repair/zed_20260621_225845

# Force sqlite .recover even if the integrity check passes:
ros2bag-repair <bag> --force-recover

Then play it as usual:

ros2 bag play /data/recordings/zed_20260621_225845

Library API

from ros2bag_repairer import repair

report = repair("/data/recordings/zed_20260621_225845")
print(report.message_count, report.recovered, report.metadata_written)

How it works

  1. db.checkpoint_wal — merges a leftover -wal into the database.
  2. db.integrity_ok / db.recover — integrity-checks the .db3 and, if it fails, rebuilds it with sqlite .recover.
  3. metadata.build_metadata — reads topics + messages and recomputes the per-topic counts, the start time, and the duration.
  4. repairer.repair — orchestrates the above and writes metadata.yaml.

Test

python -m pytest -q          # or: python tests/test_repair.py via pytest

License

Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ros2bag_repairer-0.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ros2bag_repairer-0.1.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file ros2bag_repairer-0.1.0.tar.gz.

File metadata

  • Download URL: ros2bag_repairer-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for ros2bag_repairer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dff80a348d878a5ab4ded77aa410cb9215e19ddb8ccd452877ee76c55500209e
MD5 e1b87b0c0336a670e64b5f445548b05b
BLAKE2b-256 31cc33fa05474c33b0953f4cdd71f6ae4c02dac70234c3637ac84bba1a3b7919

See more details on using hashes here.

File details

Details for the file ros2bag_repairer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ros2bag_repairer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69ce4b97e42462285fdc6303bd5f6e90a4100543e5193816e182c9e69220250f
MD5 09f29422c8276f92790a9c707c69b5fb
BLAKE2b-256 d953235f732a5c4d2d567dcf73b3dbe65603774d5d8d29b853c4924f0f7dda84

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page