Useful Scripts for nvram and traffdata

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Author Message
ventura8
DD-WRT Novice


Joined: 29 Jan 2012
Posts: 34

PostPosted: Wed Oct 03, 2012 14:18    Post subject: Useful Scripts for nvram and traffdata Reply with quote
This script makes a backup of traffdata once a year to /opt/ and deletes traffdata from nvram (can be used to backup to jffs)

run it as /opt/nvramcheck.sh &
the & is there to make the script run as a background process

The "$YEAR" -gt "2011" part is there to prevent the router to backup nvram on reboot. Some routers default to 1/1/1970 date before getting the current date thru NTP . And if you set it to backup on 1/1 it will backup after reboot, not the 1/1 of the next year

delete or comment (#) "for i in `nvram show | grep traff- | cut -f1 -d=""`; do nvram unset $i; done" if you don't want the traffdata to be deleted from nvram
Code:

#!/bin/sh
INTERVAL=600
TARGETMONTH=Jan
TARGETDAY=1

while sleep $INTERVAL
do

MONTH=` date | awk '{print $2}'`
YEAR=` date | awk '{print $6}'`
DAY=` date | awk '{print $3}'`

PART1=/opt/
PART2=traffdata.
PART3=$DAY"-"$MONTH"-"$YEAR
PART4=.bak

URL=$PART1$PART2$PART3$PART4
FILE=$PART2$PART3$PART4



STOP=0
if [[ "$MONTH" = "$TARGETMONTH" && "$DAY" = "$TARGETDAY" && "$YEAR" -gt "2011" ]]; then
for i in ` ls /opt/ |cut -f1 | grep traffdata`
do
if [ "$i" = "$FILE" ]; then
STOP=1
echo "Do nothing"
fi
done
else
echo "Not the target date"
STOP=1
fi

if [ "$STOP" = "0" ]; then
COUNT=1
echo TRAFF-DATA >> $URL
for i in `nvram show | grep traff-  | cut -f1 -d=""`;
do
NEW=` nvram show | grep traff- | awk 'NR == a {print}' a=$COUNT`
COUNT=`expr $COUNT + 1`
echo $NEW >>  $URL
done
for i in `nvram show | grep traff- | cut -f1 -d=""`; do nvram unset $i; done
fi

done;


This script checks if there is at least 1024 bytes of free nvram and if it isn't it will backup traffdata, delete traffdata from nvram and reboot

run it as /opt/backuptraff.sh &

change NVRAMSIZE to your nvramsize and INTERVAL to your liking (be careful not to create a boot loop!)

it is also useful to set upnp to clear values on reboot to be sure more nvram will be freed at reboot
(you can do this from the web gui)

Code:

#!/bin/sh
INTERVAL=60
NVRAMSIZE=61440

while sleep $INTERVAL
do

str=` nvram show `
len=`expr length "$str"`
len=`expr $len + 21`
free=`expr $NVRAMSIZE - $len`


if [ "$free" -le "1024" ]; then


MONTH=` date | awk '{print $2}'`
YEAR=` date | awk '{print $6}'`
DAY=` date | awk '{print $3}'`

PART1=/opt/
PART2=traffdata.
PART3=$DAY"-"$MONTH"-"$YEAR
PART4=.bak

URL=$PART1$PART2$PART3$PART4

COUNT=1
echo TRAFF-DATA >> $URL
for i in `nvram show | grep traff-  | cut -f1 -d=""`;
do
NEW=` nvram show | grep traff- | awk 'NR == a {print}' a=$COUNT`
COUNT=`expr $COUNT + 1`
echo $NEW >>  $URL
done
for i in `nvram show | grep traff- | cut -f1 -d=""`; do nvram unset $i; done
reboot

fi

done


In both cases the resulting traffdata.bak file is compatible with the restore function in Data Administration on the STATUS > WAN page and has a date stamp in the file name (ex: traffdata.3-Oct-2012.bak)

If you have suggestions or you found bugs in the scripts please let me know
Please modify the script to your on configuration (maybe you use jffs instead of opt, or have smaller nvram) before submiting bugs
Sponsor
Vaako
DD-WRT User


Joined: 10 Jun 2009
Posts: 370

PostPosted: Sun Feb 09, 2014 17:36    Post subject: Reply with quote
Question:

Can traffdata.bak imported/restored on any other router or does the traffdata.bak belongs Always to the router that the backup came from?

_________________
Regards,
Vaako

1x Netgear R7800 Nighthawk - firmware not decided yet !!!!
1x Netgear R7000 Nighthawk r36410
1x Ubiquiti RouterStation Pro DD-WRT r23204 std (12/24/13)
1x Asus RT-N16 SVN revision 20675 NEWD-2 K2.6
1x Linksys E4200 v3.0 r34777 mega (01/31/18 )
1x Buffalo WZR-HP-G300NH B0 B0 Gargoyle FW
1x Linksys WRT600N v1.1 (Bricked)
1x Linksys WRT54GL v1.1 (DD-WRT 26446)
1x Linksys WRT54GS v2.2 (DD-WRT 26446)
1x Linksys RVS4000 (stock fw)
3x D-Link DWL-7100AP (openWRT)
2x TP-Link TL-WA801ND (Bridge mode) 100mW TX-Power
Asus WL-520GU SVN 16403M NEWD-2 Eko std-nokaid
4x Fonera with Gargoyle FW
rseiler
DD-WRT Guru


Joined: 01 Oct 2007
Posts: 622

PostPosted: Sun Feb 09, 2014 20:30    Post subject: Reply with quote
Any other DD-WRT router. Open it up in Notepad--it's just generic lines of ASCII.
ventura8
DD-WRT Novice


Joined: 29 Jan 2012
Posts: 34

PostPosted: Thu Feb 13, 2014 11:33    Post subject: Reply with quote
Vaako wrote:
Question:

Can traffdata.bak imported/restored on any other router or does the traffdata.bak belongs Always to the router that the backup came from?


Yes, the data can be imported as long traffmon app is compatible with the format the data is saved
Vaako
DD-WRT User


Joined: 10 Jun 2009
Posts: 370

PostPosted: Sun Feb 16, 2014 21:56    Post subject: Reply with quote
Yes it does work!
Thx for the reply!

_________________
Regards,
Vaako

1x Netgear R7800 Nighthawk - firmware not decided yet !!!!
1x Netgear R7000 Nighthawk r36410
1x Ubiquiti RouterStation Pro DD-WRT r23204 std (12/24/13)
1x Asus RT-N16 SVN revision 20675 NEWD-2 K2.6
1x Linksys E4200 v3.0 r34777 mega (01/31/18 )
1x Buffalo WZR-HP-G300NH B0 B0 Gargoyle FW
1x Linksys WRT600N v1.1 (Bricked)
1x Linksys WRT54GL v1.1 (DD-WRT 26446)
1x Linksys WRT54GS v2.2 (DD-WRT 26446)
1x Linksys RVS4000 (stock fw)
3x D-Link DWL-7100AP (openWRT)
2x TP-Link TL-WA801ND (Bridge mode) 100mW TX-Power
Asus WL-520GU SVN 16403M NEWD-2 Eko std-nokaid
4x Fonera with Gargoyle FW
-DELETED_Klappis
DD-WRT Novice


Joined: 13 Apr 2014
Posts: 12

PostPosted: Thu Dec 04, 2014 11:43    Post subject: Reply with quote
How do i run this script?
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum