Keep VnStat data across reboots

Hi,

every time I reboot the Omnia for upgrade, all VnStat stats are gone, counters restart at 0. So it’s completely useless.

How do I keep the data across reboots?

Maybe look here:

2 Likes

Thanks, I have re-configured VnStat manually and also placed the database file on the SSD instead of the internal flash memory. Now in Luci, no interfaces are selected but it seems to work.

I don’t know yet if it solves the problem, I have not rebooted again. This will happen on the next upgrade which requires a reboot.

In the far past I had the following script in /etc/init.d:

bash-3.2$ cat ./vnstatbackup 
#!/bin/sh
## Please visit http://wiki.openwrt.org/doc/howto/vnstat
# 20121008sm: automate parsing of vnstat related information
# place this script in /etc/init.d
# make it executable: chmod 755 /etc/init.d/vnstatbackup
# 4 CRON: echo "*/30 * * * * /etc/init.d/vnstatbackup backup" >> /etc/crontabs/root
#  	/etc/init.d/cron restart
# 4 INIT add
# /etc/init.d/vnstatbackup restore
# to /etc/rc.local


# edit this
BACKUP_BASE_DIR="/home/persistent"	# where to store the database backup

# for vnstat have a look at /etc/vnstat.conf (code taken from /etc/init.d/vnstat)
vnstat_option() {
    sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
    /etc/vnstat.conf
}
VNSTAT_DB_DIR="$(vnstat_option DatabaseDir)"
VNSTAT_BASE_DIR=`dirname ${VNSTAT_DB_DIR}` #${VNSTAT_DB_DIR%/*}
VNSTAT_SUB_DIR=`basename ${VNSTAT_DB_DIR}` #"vnstat"

#echo "VNSTAT_DB_DIR ${VNSTAT_DB_DIR}"
#echo "VNSTAT_BASE_DIR ${VNSTAT_BASE_DIR}"
#echo "VNSTAT_SUB_DIR ${VNSTAT_SUB_DIR}"
#echo "BACKUP_BASE_DIR ${BACKUP_BASE_DIR}"

case $1 in
    backup)
	cp -r ${VNSTAT_BASE_DIR}/${VNSTAT_SUB_DIR} ${BACKUP_BASE_DIR}
        ;;
    restore)
        cp -r ${BACKUP_BASE_DIR}/${VNSTAT_SUB_DIR} ${VNSTAT_BASE_DIR}
        ;;
    *)
        echo "Please use 'backup' or 'restore' parameter for run";
	;;
esac
                          
exit 0

And the following in /etc/crontabs/root"

bash-3.2$ cat ./root
#*/30 * * * * /etc/init.d/vnstatbackup backup
#*/5 * * * * vnstat 

And finally the following in /etc/rc.local:

##manual vnstat updates... since vnstat logs to tmpfs re-init the database
mkdir /var/lib/vnstat
vnstat -u -i eth1

## to make vnstat robust against reboots (to monitor volume caps)
/etc/init.d/vnstatbackup restore

which worked pretty OK, I can not guarantee that it captured every last byte but it seemed reasonably accurate. (I long stopped being behind an ISP with a data-cap and hence never bothered to set this up on my omnia under TOS, maybe I shoukd just to check whether that still works)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.