vergoh / vnstat

vnStat - a network traffic monitor for Linux and BSD
GNU General Public License v2.0
1.36k stars 120 forks source link

how to recover the database when i modify the time and updae the database force #251

Closed jiayuyin closed 11 months ago

jiayuyin commented 11 months ago

1.Modify the systime after database time , and vnstat -i br-lan -u. 2.Modify the systime before database time, and vnstat -i br-lan -u --force 3,get a Error: br-lan Invalid database daily date order: 1688954619(0) < 1689818462(1) This database is damaged,if vnstat -i br-lan -u --force twice, the backup database also damaged how can I recover the databese , except rm * and restart vnstat.

Actually, I use npt auto to sync time, I reproduced using the above method,but I didn't use "--force" in my code.

vergoh commented 11 months ago

Which version of vnStat are you using?

Based on the output, I'm assuming it would be one of the 1.x versions. Depending on the exact version, the process of recovering from that error without fully resetting the database should be possible. The way that's done is to first export the database to a text format file using --exportdb which you'd then modify to fix the date issues in the daily data in indexes 0 and 1. Then you'd use --importdb to import those changes and overwrite the existing database. The availability of --exportdb and --importdb will depend on the version you have.

Once you've got the database recovered, I'd suggest upgrading to the latest version from the 2.x version series (assuming you don't have some exotic or minimal environment) as the new database structure is far more resilient to these kinds of issues.

vergoh commented 11 months ago

Feel free to reopen if my reply above didn't help enough.