1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

User NVRAM Save/Restore Utility (R26.2)

Discussion in 'Asuswrt-Merlin' started by john9527, Sep 15, 2014.

  1. waffles

    waffles Regular Contributor

    Joined:
    Mar 15, 2013
    Messages:
    91
    John;

    Your utility worked beautifully as far as I can tell.

    Thanks again for making it available to us!
     
  2. knighthawk

    knighthawk Occasional Visitor

    Joined:
    Nov 1, 2014
    Messages:
    21
    Location:
    US
    Yeah this is a incredibly helpful and time-saving utility. Add my voice to those asking for a sticky or given the concern about too many stickies a mention and link to it in the wiki.
     
  3. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,096
    Location:
    United States
    I've created a Wiki entry and added it to the index under 'Misc HowTo and Guides'

    Thanks again to all for the feedback.
     
  4. rtcomputersinc

    rtcomputersinc Senior Member

    Joined:
    Dec 6, 2013
    Messages:
    225
    I didn't copy it off but will check it when I get home. I was using Putty to access the router but that shouldn't be an issue.
     
  5. elorimer

    elorimer Very Senior Member

    Joined:
    Dec 16, 2013
    Messages:
    838
    A wee little thing, but a WPA2 key I was using had a "$" in it. The exported fine, but when it was reimported the $ and everything after were deleted. I assume because it was a special character.

    Along the way I also edited the outputted script to reorder the static IP list.
     
  6. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,096
    Location:
    United States
    Wow....thanks for the report on the "$". I checked and that's the only special character that behaves that way...but will work correctly if you escape the character. I'll put in a fix.

    Code:
    [email protected]:/tmp/home/root# nvram get test
    [email protected]:/tmp/home/root# nvram set test="xxxx$yyyy"
    [email protected]:/tmp/home/root# nvram get test
    xxxx
    [email protected]:/tmp/home/root# nvram set test="xxxx\$yyyy"
    [email protected]:/tmp/home/root# nvram get test
    xxxx$yyyy
    Regarding the sorting of the various list type of parameters, I don't think I'm going to try and do anything special there and just leave that for the users to change as they see fit.
     
  7. FenderToot

    FenderToot New Around Here

    Joined:
    Nov 21, 2014
    Messages:
    3
    I have the exact same problem here, have you solved it yet?
     
  8. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,096
    Location:
    United States
    Sorry you are having a problem. Here are some things to check (assuming you are using the QuickStart guide).

    First, make sure the file actually exists and has the correct permissions by entering 'ls -l' on the router (without the quotes). You should see something like this....

    Code:
    [email protected]:/mnt/ASUS# ls -l
    -rw-r--r--    1 admin    root          5062 Dec  3 21:35 QuickStart-linux.txt
    -rw-r--r--    1 admin    root          5161 Dec  3 21:34 QuickStart-win.txt
    -rwxr-xr-x    1 admin    root         24757 Dec  4 10:09 nvram-restore-20141204-E0F0.sh
    -rwxr-xr-x    1 admin    root          3231 Dec  3 14:30 nvram-save.sh
    -rw-r--r--    1 admin    root         12680 Dec  3 13:56 nvram.ini
    In this example the router mac bytes are E0F0. Note the restore file exists and has 3 x's in the permissions. If the file doesn't exist, please re-run the save portion and capture the output. If the x's aren't present, run

    Code:
    chmod a+rx nvram*.sh
    If that's all OK, open the file in the 'vi' editor, and you should see this (abbreviated some lines with ....)

    Code:
    [email protected]:/mnt/ASUS# vi nvram-restore-20141204-E0F0.sh
    
    #!/bin/sh
    
    # generated script to restore user nvram settings
    
    echo "Restoring [System - Basic]"
    nvram set time_zone_dst="0"
    nvram set time_zone="MST7_2"
    nvram set http_passwd="xxxxxxxxxx"
    nvram set http_username="admin"
    nvram set jffs2_on="1"
    nvram set jffs2_format="0"
    nvram set btn_ez_radiotoggle="0"
    nvram set ntp_server0="time-a.nist.gov"
    nvram set telnetd_enable="0"
    nvram set sshd_enable="1"
    nvram set sshd_forwarding="0"
    ....
    
    - nvram-restore-20141204-BC88.sh 1/635 0%

    If the file looks like this (with the ^M), it means at some point it was edited with a non-Linux editor and will give an error. Please re-run the save portion of the utility to recreate it.

    Code:
    #!/bin/sh^M
    # generated script to restore user nvram settings^M
    ^M
    echo "Restoring [System - Basic]"^M
    nvram set time_zone_dst="0"^M
    nvram set time_zone="MST7_2"^M
    nvram set http_passwd="xxxxxxxxxx"^M
    nvram set http_username="admin"^M
    nvram set jffs2_on="1"^M
    nvram set jffs2_format="0"^M
    nvram set btn_ez_radiotoggle="0"^M
    nvram set ntp_server0="time-a.nist.gov"^M
    nvram set telnetd_enable="0"^M
    nvram set sshd_enable="1"^M
    nvram set sshd_forwarding="0"^M
    Enter
    :q
    to exit the vi editor

    Hope this helps. Please let us know what you find....
     
  9. FenderToot

    FenderToot New Around Here

    Joined:
    Nov 21, 2014
    Messages:
    3
    Thanks for your help John, unfortunately it is still not working.
    I have indeed been following the QuickStart guide.
    The file does actually exist and seems to have the correct permissions.
    I have opened the file in the 'vi' editor and it seemed OK.

    After flashing the new firmware I tried to restore the settings but all I get is:
    -sh: nvram-restore-20141204-0480.sh: not found

    However, when I run the script to save the file and immediately thereafter (without flashing the new firmware) run the script to restore it does work.
    So once the new firmware is in place, running the script to restore no longer works.
     
  10. longstaff

    longstaff Occasional Visitor

    Joined:
    Jun 26, 2014
    Messages:
    12
    After flashing new firmware try either of the these approaches

    Use the full path to the script which assumes that the USB stick is named as per the QuickStart guide

    /mnt/ASUS/nvram-restore-20141204-0480.sh

    or to run the script in the current working directory use ./

    cd /mnt/ASUS/
    ./nvram-restore-20141204-0480.sh
     
  11. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,096
    Location:
    United States
    Do you change the login id from 'admin' to something else? If so, try changing just that one item in the gui along with the telnet setting before trying the restore.
     
  12. FenderToot

    FenderToot New Around Here

    Joined:
    Nov 21, 2014
    Messages:
    3
    Thank you very much, that worked!
     
  13. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,096
    Location:
    United States
    Interesting.....it works with or without the path in the current directory on my fork release (374.43 base) and I didn't change the PATH var. Maybe a change in the later releases. I'll update the QuickStart to include the path.
    Thanks for figuring it out.
     
  14. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,096
    Location:
    United States
    Update to....

    Version 6
    - save/restore correctly handles '$' in nvram variables
    - Update QuickStart.txt to include current path in commands - thanks to longstaff

    Thanks!
     
  15. rtcomputersinc

    rtcomputersinc Senior Member

    Joined:
    Dec 6, 2013
    Messages:
    225
    That was good someone else was having an issue like I did I didn't get a chance to test it as I was sick as hell after my post. Don't know why I didn't think to try using the full path to the file but makes sense.
     
  16. ocram59

    ocram59 Regular Contributor

    Joined:
    Feb 21, 2013
    Messages:
    67
    Hello
    Here it is a little trick that I use in my shell scripts to be sure that they always run in their directory besides how you start them
    Few lines at the beginning:

    #!/bin/sh
    BASEDIR=`dirname $0`
    cd $BASEDIR

    and there you go , no matter how you run the script (full path or ./ or any other way) it runs in the same directory where the script is saved.

    So i added them to nvram-save.sh and modified the following lines in nvram-save.sh

    echo "#!/bin/sh" >$outfile
    echo "BASEDIR=\`dirname \$0\`">>$outfile
    echo "cd \$BASEDIR" >>$outfile
    echo >>$outfile

    I let John (thanks again for your great idea and for how you mantain the script) decide if to adopt this solution or not

    BR
    Ocram
     
    Last edited: Dec 11, 2014
  17. Gerr

    Gerr New Around Here

    Joined:
    Apr 3, 2013
    Messages:
    7
    Location:
    Norway
    I've recently updated to 3.0.0.4_376.49_alpha2 and cleared nvram and restored some settings via your script. Very useful. Thanks for this script.

    I had the wireless sections commented out, because I wanted to start from scratch there, and I noticed WPS was enabled by default, so I turned WPS off from the web interface and compared nvram dumps from before and after changing the setting, by comparing these files:
    Code:
    nvram show | sort > /tmp/before
    nvram show | sort > /tmp/after
    Three nvram values changed when toggling the WPS button:
    wl0_wps_mode
    wl_wps_mode
    wps_enable

    When I was going to uncomment them in my ini I couldn't find any of them. I added them to my ini, but maybe they can also be added to the default ini, in case other users want to save the WPS on/off setting?
     
  18. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,096
    Location:
    United States
    Thanks for the feedback. I checked and there are a couple more WPS vars to also be added besides those you listed. Will definitely put them in the next ini update.
     
  19. razvanu

    razvanu Occasional Visitor

    Joined:
    May 31, 2014
    Messages:
    25
    Location:
    Romania
    Soon I'll start an update this fork on my AC68U from 04 to build 06 and I'll use this script....get back soon with results, meanwhile, thank you for this good idea.
     
  20. john9527

    john9527 Part of the Furniture

    Joined:
    Mar 28, 2014
    Messages:
    6,096
    Location:
    United States
    Won't hurt....but right now there is no need for a factory reset moving between different versions of the fork (if there ever is a reset required, I'll definitely highlight it).