Backup & restore of your Tomato-based router statistics

Since I recently moved, and now have my Tomato based WRT54GL on 24/7, I also wanted a way to keep a backup of those nice statistics the router generates. You have the option (built-in) to write them to nvram or to a CIFS share, but the former has a limited amount of writes, and the latter is not really stable (and I don’t have anything powered on all the time to keep the backups on).

I found some nice scripts on gulbsoft.de that showed how to make backups on an ftp/website combination, but I wanted to move this to an internet-host (since that thing IS up 24/7 in contrast to my inhouse infrastructure) and I didn’t really like them, I ‘redesigned’ them.

Lo and behold!

The only thing you need to do is put this in your WAN-up script:

killall rstats

URL="http://your.web.page.address"
FTP="ftp.server.name"
USER="username"
PW="password"
STATSDIR="/tmp/var/lib/misc"
FTPSCRIPT="/tmp/ftpbackup.sh"
FILES="rstats-history.gz rstats-speed.gz rstats-stime rstats-source"

cat > $FTPSCRIPT << EOF
for FILE in $FILES; do
  ftpput -u $USER -p $PW $FTP \$FILE $STATSDIR/\$FILE
done
EOF
chmod a+x $FTPSCRIPT

cru d bkstat
cru a bkstat "2,15,30,45 * * * * $FTPSCRIPT"
cd $STATSDIR
rm $FILES
for FILE in $FILES; do
  wget $URL/$FILE
done
sleep 10
rstats

Don’t forget to change the lines reading URL, FTP, USER and PW to your respective website address, ftp server name, ftp login name and ftp password!

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *