What's new

Script to Back Up & Restore Subsets of NVRAM Variable Settings.

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Martinski

Very Senior Member
I moved this thread's topic from this post as it was off-topic on that particular thread.

UPDATE [2024-Apr-10]:
The script was moved to GitHub.
The latest "0.7.12" version update is now available.

===========================================================
I see, there's however no such option on the client side. There seems to be no way to transfer VPN config/settings, not just certificates.
It is not enough to just copy the "/jffs/openvpn" folder.

At the beginning of 2021, I wrote a small shell script for a relative of mine so he could more easily & quickly back up & restore a specific subset of NVRAM variables related to his OpenVPN Server configuration (separately from his backing up the contents of the "/jffs/openvpn" folder). This was done at a time when he was having some issues with the router & needed to reset to factory defaults frequently while troubleshooting the problem.

Later on, I made more changes to add NVRAM variables for his OpenVPN client configurations. Eventually, I rewrote the script to be able to back up & restore any subset of NVRAM vars using an input file that lists the specific NVRAM variable key names targeted for backup. I recently updated the script to add a user-friendly menu (based on the code I wrote for YazDHCP).

If you're interested in trying this script, you can download it from the GitHub repository.
Here are the instructions:

1) Open an SSH terminal window & type the following commands:
Bash:
mkdir -m 755 -p /jffs/scripts
curl -kLSs --retry 3 --retry-delay 5 --retry-connrefused \
https://raw.githubusercontent.com/Martinski4GitHub/CustomMiscUtils/master/NVRAM/SaveRestoreNVRAMvars.sh \
-o /jffs/scripts/SaveRestoreNVRAMvars.sh
chmod 755 /jffs/scripts/SaveRestoreNVRAMvars.sh
NOTE: You can choose to save the script file in any other location that you prefer.

2) To run the shell script and get some brief help messages, simply go to the directory where it was saved and type:
Bash:
./SaveRestoreNVRAMvars.sh

3) I recommend running the script first in "Menu Mode" to set your preferences for the backup directory path & the input file path.
Bash:
./SaveRestoreNVRAMvars.sh -menu

4) Attached is an example of the required input file (NVRAM_VarList_SAMPLE.txt)

The input file must be saved in the same directory where the shell script is located.
Rename the file to "NVRAM_VarList.txt" & modify it as necessary for your own purposes.
===========================================================

EDIT:
Just a couple of notes:

- This script is not meant as a substitute for the built-in WebGUI option to do a full save & restore of all NVRAM variable settings. It's meant for those users who would like to back up a specific subset of NVRAM variables so that they can more quickly & easily be restored after doing a factory defaults reset of the router.

- It's up to each user to choose & decide which subsets of NVRAM variables are important enough to back up & restore.

HTH.
 

Attachments

  • NVRAM_VarList_SAMPLE.txt
    1,000 bytes · Views: 48
Last edited:
I moved this thread's topic from this post as it was off-topic on that particular thread.

UPDATE:
The version "0.7.8" update is available on PasteBin.

===========================================================


At the beginning of 2021, I wrote a small shell script for a relative of mine so he could more easily & quickly back up & restore a specific subset of NVRAM variables related to his OpenVPN Server configuration (separately from his backing up the contents of the "/jffs/openvpn" folder). This was done at a time when he was having some issues with the router & needed to reset to factory defaults frequently while troubleshooting the problem.

Later on, I made more changes to add NVRAM variables for his OpenVPN client configurations. Eventually, I rewrote the script to be able to back up & restore any subset of NVRAM vars using an input file that lists the specific NVRAM variable key names targeted for backup. I recently updated the script to add a user-friendly menu (based on the code I wrote for YazDHCP).

If you're interested in trying this script, you can download it from PasteBin (www.pastebin.com)
Here are the instructions:

1) Open an SSH terminal window & type the following commands:
Bash:
mkdir -m 755 -p /jffs/scripts
curl -kLSs --retry 3 --retry-delay 5 --retry-connrefused pastebin.com/raw/eUEtWtEc | tr -d '\r' > /jffs/scripts/SaveRestoreNVRAMvars.sh
chmod 755 /jffs/scripts/*.sh
NOTE: You can choose to save the script file in any other location that you prefer.

2) To run the shell script and get some brief help messages, simply go to the directory where it was saved and type:
Bash:
./SaveRestoreNVRAMvars.sh

3) I recommend running the script first in "Menu Mode" to set your preferences for the backup directory & input file path.
Bash:
./SaveRestoreNVRAMvars.sh -menu

4) Attached is an example of the required input file (NVRAM_VarList_SAMPLE.txt)

The input file must be saved in the same directory where the shell script is located.
Rename the file to "NVRAM_VarList.txt" & modify it as necessary for your own purposes.
===========================================================

EDIT:
Just a couple of notes:

- This script is not meant as a substitute for the built-in WebGUI option to do a full save & restore of all NVRAM variable settings. It's meant for those users who would like to back up a specific subset of NVRAM variables so that they can more quickly & easily be restored after doing a factory defaults reset of the router.

- It's up to each user to choose & decide which subsets of NVRAM variables are important enough to back up & restore.

HTH.
Is there an easy way to get all the NVRAM variable key names with their current values as a txt file? I'm thinking of importing that file into Excel to figure out what variables I want, then have Excel write a file with just those names that SaveRestoreNVRAMvars can use.
 
Is there an easy way to get all the NVRAM variable key names with their current values as a txt file? I'm thinking of importing that file into Excel to figure out what variables I want, then have Excel write a file with just those names that SaveRestoreNVRAMvars can use.
nvram show >> nvram.txt
 
Is there an easy way to get all the NVRAM variable key names with their current values as a txt file? I'm thinking of importing that file into Excel to figure out what variables I want, then have Excel write a file with just those names that SaveRestoreNVRAMvars can use.
No need to respond. I think I figured it out.
 
Is there an easy way to get all the NVRAM variable key names with their current values as a txt file?
For the record and in case anyone else is interested or curious, here's a way to make sure the var key names are nicely sorted alphabetically so you get all related key names grouped together, next to each other:
Bash:
nvram show 2>/dev/null | sort -fd -t '=' -k 1 > NVRAM_vars_sorted.txt
 
Doesn't "nvram show" ommit some sensitive variables though?
I think "nvram save" is better choice as it produces CFG style file (and doesn't seem to skip sensitive variables) which can then be decoded into variable=>value array string.

For example first command will not contain Asus DDNS token while the second will.
 
Last edited:
What about the values for the VPN Director and the Network Services Filter? It does not appear those are stored in NVRAM. Are they settable from the command line?
 
For the record and in case anyone else is interested or curious, here's a way to make sure the var key names are nicely sorted alphabetically so you get all related key names grouped together, next to each other:
Bash:
nvram show 2>/dev/null | sort -fd -t '=' -k 1 > NVRAM_vars_sorted.txt
Ahh, hopefully a way to help reduce the anxiety of a factory reset. Thanks @Martinski .
Now - to figure out which nvram variables are "safe" to safe/restore.

BTW, I made a quick tweak to not show keys with a null variable (and a tee to create a csv file)

Code:
nvram show 2>/dev/null | sort -fd -t '=' -k 1 | awk 'BEGIN { FS="=" }  {if ($2) print $0;}' | tee NVRAM_vars.txt | tr -s "=" "," > NVRAM_vars.csv
 
What about the values for the VPN Director and the Network Services Filter? It does not appear those are stored in NVRAM. Are they settable from the command line?
Oops, looks like the Network Services Filter data is in there.
 
@Martinski might put your good coding skills to the test or challenge yourself and finish what you started as the new NVRAM save and restore addon.
For current models - I removed the outdated version from @Xentrk - RIP, you were a good fellow.
 
@Martinski might put your good coding skills to the test or challenge yourself and finish what you started as the new NVRAM save and restore addon.
For current models - I removed the outdated version from @Xentrk - RIP, you were a good fellow.
It is already built into @Viktor Jaep's BACKUPMON.
 
Last edited:
It is built into @Viktor Jaep's BACKUPMON.
Yeah, but this is even more fine tuned for certain sections of the NVRAM. @Martinski... would something like this allow someone to bring over these NVRAM variables from one certain model router (like an AC86U), and upgrade to a different model router (like a GT-AX6000)? Or would you recommend not risking it, and starting from scratch in a scenario like that?
 
@Martinski might put your good coding skills to the test or challenge yourself and finish what you started as the new NVRAM save and restore addon.
For current models - I removed the outdated version from @Xentrk - RIP, you were a good fellow.
I thought the same thing - knowing that other such as Xentrk and @Martineau did do some work on the now outdated NVRAM Save/Restore.
But, then I remembered why that script was doomed. The number of changes, new features/nvram variables, differences between hardware and software releases make it almost impossible to keep up.

The more I think about this version (with a user supplied list) it makes sense.

The real trick will be finding the appropriate nvram keys for the various functions you use. SSID, vpn, port forwarding settings etc. are fairly well known. But others not as clear.

It would be nice to start a thread with keys for this script. Like the appropriate keys for Wireguard, AiMesh, etc.

I did a quick wc -l on an extracted nvram file (with keys that have no value removed) - and on my AX88U Pro there are 2062 keys...
Many have to do with (what appears) values loaded into the various registers for hardware (never touch/change these!!!)

It would be great to go back to the days of NSRU - where FOMO after a factory reset is eliminated ;-)
 
Ahh, hopefully a way to help reduce the anxiety of a factory reset. Thanks @Martinski .
Now - to figure out which nvram variables are "safe" to safe/restore.

BTW, I made a quick tweak to not show keys with a null variable (and a tee to create a csv file)

Code:
nvram show 2>/dev/null | sort -fd -t '=' -k 1 | awk 'BEGIN { FS="=" }  {if ($2) print $0;}' | tee NVRAM_vars.txt | tr -s "=" "," > NVRAM_vars.csv
Great tip!! Thanks.
 
@Martinski might put your good coding skills to the test or challenge yourself and finish what you started as the new NVRAM save and restore addon.

I thought the same thing - knowing that other such as Xentrk and @Martineau did do some work on the now outdated NVRAM Save/Restore.
But, then I remembered why that script was doomed. The number of changes, new features/nvram variables, differences between hardware and software releases make it almost impossible to keep up.
Yes, those are exactly the reasons why I prefer the current mechanism where the user supplies the desired list of NVRAM vars to save & restore. The script is agnostic when it comes to different hardware revisions, firmware versions, or added/deleted features; the expectation is that users will eventually learn which subsets of NVRAM vars they want to save & back up.

The more I think about this version (with a user supplied list) it makes sense.

The real trick will be finding the appropriate nvram keys for the various functions you use. SSID, vpn, port forwarding settings etc. are fairly well known. But others not as clear.

It would be nice to start a thread with keys for this script. Like the appropriate keys for Wireguard, AiMesh, etc.
Attached is another example of the required input file that contains more NVRAM vars, including simple regular expressions for WireGuard (server & clients) & wireless network settings (2.4 & 5 GHz). I have not vetted all these myself, but a friend of mine is using it for his own router (RT-AX86U).
 

Attachments

  • NVRAM_VarList_Group2.txt
    1.2 KB · Views: 21
Yeah, but this is even more fine tuned for certain sections of the NVRAM. @Martinski... would something like this allow someone to bring over these NVRAM variables from one certain model router (like an AC86U), and upgrade to a different model router (like a GT-AX6000)? Or would you recommend not risking it, and starting from scratch in a scenario like that?
I originally wrote the script to target specific subsets of NVRAM vars so that they could be easily saved & restored onto the same router model after doing a factory defaults reset; but the code does not actually check whether you're indeed restoring the NVRAM vars onto the same router model, so technically you could transfer the saved NVRAM settings onto a completely different router model because the code does not prevent it. In such cases, the results would be unpredictable. IMO, the script gives you a "long rope" to do safe & fast backups when used as intended, but it's up to each user to decide if they want to take risks and possibly hang themselves with the long rope.
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top