+ Reply to Thread
Results 1 to 6 of 6

Thread: How to Backup the Tomato Firmware's Bandwidth Logs (Rstats) to a FTP Server

  1. #1
    Resident Nutter InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter's Avatar
    Join Date
    May 2007
    Location
    Yorkshire, England, UK
    Posts
    4,458
    Blog Entries
    11

    Default How to Backup the Tomato Firmware's Bandwidth Logs (Rstats) to a FTP Server

    If your router is running the Tomato firmware you will probably be aware the router can log your bandwidth usage, the bandwidth log could be useful if you have a limit each month or just want to keep track of your internet usage.

    In its default configuration the router will lose the logs when its powered down or re started, this guide will show you how to automatically backup the logs to a remote ftp server every 12 hours.

    Before you begin you will need some ftp space on a remote server, if you have some free webspace on your isp’s server this will be perfect.

    1] First log on to your router then go to Administration > Scripts or http://192.168.1.1/admin-scripts.asp

    2] In the shutdown box add:
    Code:
    if [ ! -s /tmp/restore-rstats ] ; then  {make sure any previous restore was successful, or we will overwrite the backup with nothing...}
    /tmp/backup-rstats
    fi
    3] In the wan up box add:

    Code:
    USER="FTP Username"
    PASS="FTP Password"
    PORT=21
    SERVER="IP or Hostname of the FTP server"
    RPATH="/rstats.tgz"
    RPATH_DATE="/rstats\`date +%Y.%m.%d-%H.%M.%S\`.tgz"
    LPATH="/tmp/rstats.tgz"
     
    if [ ! -s /tmp/backup-rstats ] ; then
        echo -e "#!/bin/sh\nkillall -1 rstats\nsleep 1\ntar -czf \"$LPATH\" /tmp/var/lib/misc/rstats-*\nftpput -u \"$USER\" -p \"$PASS\" -P $PORT $SERVER \"$RPATH\" \"$LPATH\"\nftpput -u \"$USER\" -p \"$PASS\" -P $PORT $SERVER \"$RPATH_DATE\" \"$LPATH\"\nrm \"$LPATH\"" > /tmp/backup-rstats
        chmod 777 /tmp/backup-rstats
        echo -e "#!/bin/sh\nservice rstats stop\nftpget -u \"$USER\" -p \"$PASS\" -P $PORT $SERVER \"$LPATH\" \"$RPATH\"" > /tmp/restore-rstats
        echo -e "if [ \$? != 0 ] ; then\n  logger RStats Restore Failed... will retry\n  cru a rstats \"*/5 * * * * /tmp/restore-rstats\"\n  return 1\nfi\ntar -xzf \"$LPATH\" -C /\nrm \"$LPATH\"\nservice rstats start\ncru a rstats \"1 */12 * * * /tmp/backup-rstats\"" >> /tmp/restore-rstats
        echo -e "logger RStats Data Restored\nrm /tmp/restore-rstats" >> /tmp/restore-rstats
        chmod 777 /tmp/restore-rstats
        /tmp/restore-rstats
    fi
    Modify your FTP username, password, port and hostname as appropriate.

    Thats it, your good to go!

    You can test this works by surfing the net for a bit or downloading something, then use the shutdown button on the routers web interface. It should upload the bandwidth logs then download them again when the router re starts. (it can take a minute or two after the router loading up for the logs to appear again)

    I take no credit for creating the script used in this guide, I found it on a random website after spending a long while looking for a solution to backup the logs to a remote server.

  2. Thanks from:


  3. #2
    The Feature Man xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx's Avatar
    Join Date
    Aug 2008
    Location
    Destiny
    Posts
    1,743
    Blog Entries
    21

    Default

    I was just working on doing this the other day. Nimrod was asking why was I even bothering and to just use some program. I couldn't find anything useful on the net. Though tonight I was searching on Google very hard for a good script and I was amazed at what site I finally was returned to...DIGIEX!!! I'm glad you already have a guide for this.

    Quick qustion though, is there anyway to change it to back up sooner then every 12 hours? What if your router dies, electric dies, a tornado come through and you want that data to be preserved.

    I have a ftp server running on my PC at the moment InsaneNutter but do you think it would be better to back this data up to my webspace here?

  4. #3
    Resident Nutter InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter's Avatar
    Join Date
    May 2007
    Location
    Yorkshire, England, UK
    Posts
    4,458
    Blog Entries
    11

    Default

    I think it would be better to backup to a remote server such as your Digiex webspace. A dedicated server should be online 24/7, at some point your pc is not going to be on when your router wants to backup the bandwidth logs. (especially as you like installing new Windows 7 builds)

    The advantage of doing the bandwidth monitoring with your router is that it will log the bandwidth used by every device on your network and not just a pc running an application to do so, this means the bandwidth used by the 360 and other games consoles will also be logged.

    To change when the logs are backed up I think you would find "1 */12 * * * /tmp/backup-rstats" and modify the 12 to 1 for example if you want the backup to run every hour.

    The script has been working perfectly for the last 1 and a half years now.
    Attached Thumbnails Attached Thumbnails How to Backup the Tomato Firmware's Bandwidth Logs (Rstats) to a FTP Server-logs.jpg  

  5. #4
    The Feature Man xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx has much to be proud of xzKinGzxBuRnzx's Avatar
    Join Date
    Aug 2008
    Location
    Destiny
    Posts
    1,743
    Blog Entries
    21

    Default

    Finally got it working fully today. Of course this picture is mostly showing all your rstats since you sent me yours. Though its backing up once every hour to my user webspace here. which is behind a webpage so no one should be able to see it inless they access it via a ftp client which to my knowledge doesn't work without a user and pass.

    Thanks for helping me today on MSN. I turned out leaving the shutdown code as it was and changing the wan up script a little to this. so it replaces the old file on the server instead on creating a new one each time.

    Code:
    USER="PUT FTP USERNAME HERE"
    PASS="PUT FTP PASSWORD HERE"
    PORT=PUT FTP PORT HERE
    SERVER="PUT FTP HOST HERE IP OR HOSTNAME"
    RPATH="/Router/rstats.tgz" WHERE IT SAYS ROUTER YOU CAN CHANGE THAT TO BE ANYTHING. LETS SAY IF IT SAYS "/ROUTER/RSTATS.TGZ" THEN IT TELLS THIS SCRIPT TO MAKE THE FILE RSTATS.TGZ IN THE REMOTE PATH /ROUTER WHICH IS A FOLDER I HAVE CREATED ON MY WEBSPACE. (DELETE THIS IF YOU INTEND TO USE IT)
    LPATH="/tmp/rstats.tgz"
     
    if [ ! -s /tmp/backup-rstats ] ; then
        echo -e "#!/bin/sh\nkillall -1 rstats\nsleep 1\ntar -czf \"$LPATH\" /tmp/var/lib/misc/rstats-*\nftpput -u \"$USER\" -p \"$PASS\" -P $PORT $SERVER \"$RPATH\" \"$LPATH\"\nftpput -u \"$USER\" -p \"$PASS\" -P $PORT $SERVER \"$LPATH\"\nrm \"$LPATH\"" > /tmp/backup-rstats
        chmod 777 /tmp/backup-rstats
        echo -e "#!/bin/sh\nservice rstats stop\nftpget -u \"$USER\" -p \"$PASS\" -P $PORT $SERVER \"$LPATH\" \"$RPATH\"" > /tmp/restore-rstats
        echo -e "if [ \$? != 0 ] ; then\n  logger RStats Restore Failed... will retry\n  cru a rstats \"*/5 * * * * /tmp/restore-rstats\"\n  return 1\nfi\ntar -xzf \"$LPATH\" -C /\nrm \"$LPATH\"\nservice rstats start\ncru a rstats \"1 */1 * * * /tmp/backup-rstats\"" >> /tmp/restore-rstats
        echo -e "logger RStats Data Restored\nrm /tmp/restore-rstats" >> /tmp/restore-rstats
        chmod 777 /tmp/restore-rstats
        /tmp/restore-rstats
    fi
    As you can see it updated the file on the server at 11:01!!!!! Thanks again!
    Attached Thumbnails Attached Thumbnails How to Backup the Tomato Firmware's Bandwidth Logs (Rstats) to a FTP Server-capture.png   How to Backup the Tomato Firmware's Bandwidth Logs (Rstats) to a FTP Server-capture1.png  

  6. #5
    Resident Nutter InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter has much to be proud of InsaneNutter's Avatar
    Join Date
    May 2007
    Location
    Yorkshire, England, UK
    Posts
    4,458
    Blog Entries
    11

    Default

    Glad you got it working

    I think the idea of having it creating a separate file is so if an upload was to fail or the file got corrupted you could just restore another backup and not lose everything.
    As the files are only a few kb i left it be.

    No idea who created the script but a big thanks to them!

  7. #6
    Stayed to Post mathieumg is on a distinguished road
    Join Date
    Aug 2009
    Posts
    1

    Default

    Hi,

    I found this thread when Googling to find a way to backup my bandwidth stats on my Tomato (v1.25 running on WRT54GL v1.1). I put the appropriate scripts both in Shutdown and WAN up but when I reboot my router (even multiple times) it won't do anything. When I navigate to Daily and Weekly stats pages, I get empty tables and the Monthly page gives me a "The rstats program is not responding or is busy. Try reloading after a few seconds." error. I've made sure all the FTP info was correct and tested it with Filezilla. Also, no file gets uploaded to the ftp I would like to know if someone has a clue as to what the problem could be.

    Thank you very much in advance!

    Edit: Nevermind, I uploaded the stats file I had backed up from the router interface to the FTP and renamed it rstats.tgz and it seems to have done the trick!

+ Reply to Thread

Similar Threads

  1. Digiex’s Bandwidth Usage
    By InsaneNutter in forum General Chat
    Replies: 2
    Last Post: 19-11-09, 06:24
  2. DDWRT or Tomato
    By MasterChief in forum Computer Discussion and Help Center
    Replies: 7
    Last Post: 13-11-09, 19:35
  3. Take Back Your Bandwidth
    By LiquidBlack in forum Guides and Tutorials
    Replies: 14
    Last Post: 29-10-09, 12:17
  4. Replies: 0
    Last Post: 10-09-08, 11:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts