vergoh / vnstat

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

Migrate from `vnstat` to `vnstat2` #217

Closed agneevX closed 2 years ago

agneevX commented 2 years ago

Hello,

I've been using vnstat for a while now, but noticed that vnstat2 is now available.

What's the best way to move the current DBs over, if it can be moved over?

Currently the DBs are stored in /tmp/mnt/sda1/entware/var/lib/vnstat folder.

Appreciate any help, thanks.

vergoh commented 2 years ago

There's no vnstat2 from my side being released so I have to assume that you are referring to how some distribution has done the binary packaging and instead of continuing with vnstat they've opted to branch to vnstat2 when vnStat 2.0 was released in October 2018.

vnStat supports keeping all the data when upgrading from version 1.x to version 2.x. The only requirement is that the old database files from version 1.x are kept in the same database directory as version 2.x is configured to be using during the first startup of the daemon (vnstatd). If the version 2.x daemon doesn't find the new format database in the directory but finds old format databases then it will proceed in importing all the data to the new format, reconstruct "yearly" data from what's available and leave the old database files untouched. Any later restart when the new format database already exists will no longer result in the import being executed and the old database files can be removed from the directory as a result.

It may help to also check the change notes starting from the release you are currently using: https://github.com/vergoh/vnstat/blob/master/CHANGES There's also a list of new configuration options per release available: https://github.com/vergoh/vnstat/blob/master/UPGRADE.md

agneevX commented 2 years ago

Thanks for the info. The migration was done exactly as you said and there have been no issues.

@vergoh is it safe to delete the old files?

# ls -lah /tmp/mnt/sda1/entware/var/lib/vnstat/
drwxr-xr-x    2 root     0           4.0K Dec 30 16:57 .
drwxr-xr-x    4 root     0           4.0K May 18  2021 ..
-rw-r--r--    1 root     0           2.7K Dec 30 16:52 .ath0
-rw-r--r--    1 root     0           2.7K Dec 30 16:52 .ath1
-rw-r--r--    1 root     0           2.7K Dec 30 16:52 .ath2
-rw-r--r--    1 root     0           2.7K Dec 30 16:52 .eth0
-rw-r-----    1 root     0           2.7K Dec 30 16:52 .eth1
-rw-r--r--    1 root     0           2.7K Dec 30 16:52 ath0
-rw-r--r--    1 root     0           2.7K Dec 30 16:52 ath1
-rw-r--r--    1 root     0           2.7K Dec 30 16:52 ath2
-rw-r--r--    1 root     0           2.7K Dec 30 16:52 eth0
-rw-r--r--    1 root     0           2.7K Dec 30 16:52 eth1
-rw-r--r--    1 root     0          76.0K Dec 30 16:57 vnstat.db

Pasting the logs here in case anyone else stumbles on to this...

Expand... ```sh # opkg install vnstat2 Installing vnstat2 (2.8-2) to root... Collected errors: * check_conflicts_for: The following packages conflict with vnstat2: * check_conflicts_for: vnstat * * opkg_install_cmd: Cannot install package vnstat2. # opkg remove vnstat Removing package vnstat from root... Not deleting modified conffile /opt/etc/vnstat.conf. # opkg install vnstat2 Installing vnstat2 (2.8-2) to root... Downloading http://www.voxel-firmware.com/Downloads/Voxel/Entware/Entware-3x-Vox el/vnstat2_2.8-2_cortex-a15-3x.ipk Installing libsqlite3 (3330000-2) to root... Downloading http://www.voxel-firmware.com/Downloads/Voxel/Entware/Entware-3x-Voxel/libsqlite3_3330000-2_cortex-a15-3x.ipk Configuring libsqlite3. Configuring vnstat2. Collected errors: * resolve_conffiles: Existing conffile /opt/etc/vnstat.conf is different from the conffile in the new package. The new conffile will be placed at /opt/etc/vnstat.conf-opkg. # ./tmp/mnt/sda1/entware/etc/init.d/S32vnstat2 restart Point right interface(s) to monitor, like `vnstat -u -i ppp0`. Remove -i ppp0 to monitor all of them. Shutting down vnstatd... done. Starting vnstatd... done. # vnstat -h eth0 / hourly hour rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- 12/29/21 17:00 3.08 GiB | 419.44 MiB | 3.49 GiB | 8.33 Mbit/s 18:00 516.16 MiB | 294.51 MiB | 810.67 MiB | 1.89 Mbit/s ... ```
vergoh commented 2 years ago

Yes, the old files (*th*) can be deleted. vnstat.db now contains all the data vnStat 2.x uses regardless of the number of interfaces being monitored.