ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ros2 bag reindex fails after bag not shutdown correctly

asked 2022-11-10 17:54:18 -0600

If a ros2 bag record is interrupted through a power cut, it is likely that the sqlite3 database will be corrupted, and attempts to repair the bagfile through ros2 bag reindex will fail with an sqlite3 error. Sort of like:

As explained here this is desired behaviour in ros2 bag for writing speed reasons. However, how do you recover such a bag?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-11-10 17:57:06 -0600

TLDR;

Assuming your bag file is called

Install the application sqlite3 through

apt install sqlite3

Check for issues in db3 file in bag.

sqlite3 /path/to/bag/bag.db3 "PRAGMA integrity_check;"

Now I have seen the above command return errors or ok with no change to the reindexing success for rosbag2. Make a backup of the database:

 cp bag/bag.db3 bag/bag.db.bak
 sqlite3 bag/bag.db3

At the prompt dump the raw contents of the db.

.mode insert
.output bag/dump_all.sql
.dump
.exit

Use grep to extract just the relevant transactions (remember I don't know sql)

cat bag/dump_all.sql | grep -v TRANSACTION | grep -v ROLLBACK | grep -v COMMIT >bag/dump_all_notrans.sql

now load back into a new database:

 sqlite3 bag/bag.db3 ".read bag/dump_all_notrans.sql"

check that the size of the database is no longer zero

ls -al bag/bag.db3

Now you should be able to reindex successfully:

ros2 bag reindex bag/

Note that for a performance penalty there is an argument --storage-preset-profile resilent that is supposed to record ros2 bags in a more recoverable way.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-11-10 17:54:18 -0600

Seen: 858 times

Last updated: Nov 10 '22