Backup settings and restore them to even different hardware.

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page Previous  1, 2, 3, 4, 5 ... 22, 23, 24  Next
Author Message
smurphster
DD-WRT Novice


Joined: 03 Apr 2008
Posts: 15
Location: Oshkosh, WI

PostPosted: Tue Apr 07, 2009 1:07    Post subject: Reply with quote
solved! i re-did my vars file and it works. possibly had the wrong end-line characters in there (damn windows)

thanks to frater and dellsweig!

_________________
WRT54GL 1.1 V24-preSP2 VPN
WAPBR-100 V24-preSP2 micro
Sponsor
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Thu Apr 16, 2009 7:06    Post subject: Reply with quote
Replacing the line:

Code:
    echo -n "${data}" | sed 's/\\/\\\\/g' | sed 's/`/\\`/g' | sed 's/\$/\\\$/g' | sed 's/\"/\\"/g' | tee -ia  ${TO_ALL} >> ${bfile}

with
Code:
    echo -n "${data}" | sed -e 's/\\/\\\\/g' -e 's/`/\\`/g' -e 's/\$/\\\$/g' -e 's/\"/\\"/g' | tee -ia  ${TO_ALL} >> ${bfile}

Could make the script a bit faster and neater.

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Thu Apr 16, 2009 19:00    Post subject: Reply with quote
frater wrote:
Replacing the line:

Code:
    echo -n "${data}" | sed 's/\\/\\\\/g' | sed 's/`/\\`/g' | sed 's/\$/\\\$/g' | sed 's/\"/\\"/g' | tee -ia  ${TO_ALL} >> ${bfile}

with
Code:
    echo -n "${data}" | sed -e 's/\\/\\\\/g' -e 's/`/\\`/g' -e 's/\$/\\\$/g' -e 's/\"/\\"/g' | tee -ia  ${TO_ALL} >> ${bfile}

Could make the script a bit faster and neater.


or even better..
Code:
echo -n "${data}" |  sed -e 's/[$`"\]/\\&/g' | tee -ia  ${TO_ALL} >> ${bfile}

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
Slione
DD-WRT User


Joined: 05 Dec 2007
Posts: 215
Location: Michigan

PostPosted: Sun Apr 19, 2009 15:14    Post subject: Reply with quote
frater wrote:
frater wrote:
Replacing the line:

Code:
    echo -n "${data}" | sed 's/\\/\\\\/g' | sed 's/`/\\`/g' | sed 's/\$/\\\$/g' | sed 's/\"/\\"/g' | tee -ia  ${TO_ALL} >> ${bfile}

with
Code:
    echo -n "${data}" | sed -e 's/\\/\\\\/g' -e 's/`/\\`/g' -e 's/\$/\\\$/g' -e 's/\"/\\"/g' | tee -ia  ${TO_ALL} >> ${bfile}

Could make the script a bit faster and neater.


or even better..
Code:
echo -n "${data}" |  sed -e 's/[$`"\]/\\&/g' | tee -ia  ${TO_ALL} >> ${bfile}


@frater
I did not use the first change you made to this but I did use the second one and when I attempted to restore the essential settings it came back with an error: line 134 unexpected "(".

I looked through the vars and found this which has something to do with UPnP I think:

nvram set forward_port3="3074-3074>192.168.1.169:3074-3074,udp,on,Xbox (192.168.1.169:3074) 3074 UDP

Any ideas on why that may have happened? Confused

_________________
WRT1900AC v1-build r30731
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sun Apr 19, 2009 18:08    Post subject: Reply with quote
Besides the missing last double quote, there's no error in that line.
The error might be in a preceding line...

Can you post a bigger part of the file.. some more preceding lines....

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
Slione
DD-WRT User


Joined: 05 Dec 2007
Posts: 215
Location: Michigan

PostPosted: Mon Apr 20, 2009 1:14    Post subject: Reply with quote
frater wrote:
Besides the missing last double quote, there's no error in that line.
The error might be in a preceding line...

Can you post a bigger part of the file.. some more preceding lines....


Here you go let me know if you need more. :)

nvram set forward_port0="80-80>192.168.1.160:80-80,tcp,on,WHS_80nvram set forward_port1="443-443>192.168.1.160:443-443,tcp,on,WHS_443nvram set forward_port2="4125-4125>192.168.1.160:4125-4125,tcp,on,WHS_4125nvram set forward_port3="3074-3074>192.168.1.169:3074-3074,udp,on,Xbox (192.168.1.169:3074) 3074 UDPnvram set forward_spec="Teamspeak:on:udp:8767>192.168.1.160:8767nvram set forwardspec_entries="1nvram set fullswitch="0nvram set fw_disable="0nvram set generate_key="0nvram set gozila_action="0nvram set hb_server_domain=

_________________
WRT1900AC v1-build r30731
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Mon Apr 20, 2009 14:00    Post subject: Reply with quote
It is missing the end quotes and last carriage return...

I think you have killed a line too many

Code:
echo -en "nvram set ${var}=\"" | tee -ia ${TO_ALL} >> ${bfile}
echo -n "${data}" |  sed -e 's/[$`"\]/\\&/g' | tee -ia  ${TO_ALL} >> ${bfile}
echo -e "\"" | tee -ia  ${TO_ALL} >> ${bfile}


I think you're missing the last line.....

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
dellsweig
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 1476
Location: New York, USA

PostPosted: Mon Apr 20, 2009 14:12    Post subject: Reply with quote
frater wrote:
It is missing the end quotes and last carriage return...

I think you have killed a line too many

Code:
echo -en "nvram set ${var}=\"" | tee -ia ${TO_ALL} >> ${bfile}
echo -n "${data}" |  sed -e 's/[$`"\]/\\&/g' | tee -ia  ${TO_ALL} >> ${bfile}
echo -e "\"" | tee -ia  ${TO_ALL} >> ${bfile}


I think you're missing the last line.....


Note to EVERYONE out there messing with this script.

This script is Unix shell scripting. If you dont know what youre doing you should not mess with it.

Also - line termination characters differ between Windowz and Linux. If you use notepad or wordpad in Windowz to edit these files you WILL have problems.
A better choice for windowz would be VIM or Notepad++

One bad edit could cause bad values to be written to NVRAM and brick your router.
smurphster
DD-WRT Novice


Joined: 03 Apr 2008
Posts: 15
Location: Oshkosh, WI

PostPosted: Mon Apr 20, 2009 20:11    Post subject: Reply with quote
dellsweig wrote:

Also - line termination characters differ between Windowz and Linux. If you use notepad or wordpad in Windowz to edit these files you WILL have problems.
A better choice for windowz would be VIM or Notepad++


i copy/pasted from a windows machine into cygwin (i thought converted them) which where i had problems. if you're having problems, grab "tofrodos" and run "dos2unix" on the script and vars file. normally i don't even use windows but my linux box was down at the time Sad.

_________________
WRT54GL 1.1 V24-preSP2 VPN
WAPBR-100 V24-preSP2 micro
Slione
DD-WRT User


Joined: 05 Dec 2007
Posts: 215
Location: Michigan

PostPosted: Mon Apr 20, 2009 21:44    Post subject: Reply with quote
frater wrote:
It is missing the end quotes and last carriage return...

I think you have killed a line too many

Code:
echo -en "nvram set ${var}=\"" | tee -ia ${TO_ALL} >> ${bfile}
echo -n "${data}" |  sed -e 's/[$`"\]/\\&/g' | tee -ia  ${TO_ALL} >> ${bfile}
echo -e "\"" | tee -ia  ${TO_ALL} >> ${bfile}


I think you're missing the last line.....


Embarassed You are correct Frater, I deleted more than I should have. Thanks.

_________________
WRT1900AC v1-build r30731
RjG
DD-WRT User


Joined: 01 Jul 2007
Posts: 81

PostPosted: Tue Apr 21, 2009 8:31    Post subject: Reply with quote
This is very cool... You guys saved me lots of typing :-)

I did find it made things not work very well when trying to go between models. Since I don't know what all the vars are for, and what's safe to keep between versions - I went a different route and modified your script to generate an additional script just for the (very safe) stuff I usually set by hand after setting to default Smile

This modification of your great script keeps your dangerous script as is, then splits the essential stuff into what you picked, plus a new "PREFERRED" script. You can pick and choose to put whatever you want in the preferred script by adding to vars_preferred file.

The one I attached is the one I use, and it sets up DHCP/DNS, static IPs, domain, timezone, port forwarding etc etc. The generated preferred.sh script is the -only- one I run after a reset-to-default to be up and running in a few seconds.

note-the wireless password needs to be set/unset/set again - on purpose since I didn't want to copy all of those variables between versions, I only wanted to save the password. Otherwise, it's plug and play between a 54GL, 54GSv2, and a SL54GS :-)


Code:

#!/bin/sh
#
# This shell script creates a shell file with lines of the form
# nvram set x="y"
# for every nvram variable found from
# nvram show
#
DATE=`date +%m%d%Y`
MAC=`nvram get lan_hwaddr | tr -d ":"`
FILE=${MAC}.${DATE}
CUR_DIR=`dirname $0`
FOLDER=/mnt
TO_ALL=${FOLDER}/${MAC}.${DATE}.all.sh
TO_INCLUDE=${FOLDER}/${MAC}.${DATE}.essential.sh
TO_EXCLUDE=${FOLDER}/${MAC}.${DATE}.dangerous.sh
TO_PREFERRED=${FOLDER}/${MAC}.${DATE}.preferred.sh
#FTPS=ftp://192.168.10.210/backups
#vUSERPASS=user:pass
nvram show 2>/dev/null | egrep '^[a-zA-Z].*=' | awk -F= '{print $1}' | grep -v "[ /+<>,:;]" | sort -u >/mnt/all_vars
#
echo -e "#!/bin/sh\n#\necho \"Write variables\"\n" | tee -i ${TO_EXCLUDE} | tee -i ${TO_ALL} > ${TO_INCLUDE}
cat /mnt/all_vars | while read var
do
if echo ${var} | grep -q -f "${CUR_DIR}/vars_to_skip" ; then
bfile=$TO_EXCLUDE
else
  if echo ${var} | grep -q -f "${CUR_DIR}/vars_preferred" ; then
     bfile=$TO_PREFERRED
  else
     bfile=$TO_INCLUDE
  fi
fi
# get the data out of the variable
data=`nvram get ${var}`
if [ "${data}" == "" ] ; then
echo -e "nvram set ${var}=" | tee -ia ${TO_ALL} >> ${bfile}
else
# write the var to the file and use \ for special chars: (\$`")
echo -en "nvram set ${var}=\"" | tee -ia ${TO_ALL} >> ${bfile}
echo -n "${data}" | sed 's/\\/\\\\/g' | sed 's/`/\\`/g' | sed 's/\$/\\\$/g' | sed 's/\"/\\"/g' | tee -ia ${TO_ALL} >> ${bfile}
echo -e "\"" | tee -ia ${TO_ALL} >> ${bfile}
fi
done
rm /mnt/all_vars
echo -e "\n# Commit variables\necho \"Save variables to nvram\"\nnvram commit" | tee -ia ${TO_ALL} | tee -ia ${TO_EXCLUDE} >> ${TO_INCLUDE}
chmod +x ${TO_ALL}
chmod +x ${TO_INCLUDE}
chmod +x ${TO_EXCLUDE}
chmod +x ${TO_PREFERRED}


All the files are attached, since copy/pasting from web pages is evil, nasty spaces and linefeeds mucks everything up dangerously, as mentioned

Use the mnt script on your usb drive if you have it, or tmp if you use the other method previously explained, both are attached. The instructions are the same as given before, no need to repeat them again.

I hope you don't mind the modification. All credit goes to the previous author, very nice stuff.



backupvars.zip
 Description:
backup scripts

Download
 Filename:  backupvars.zip
 Filesize:  1.79 KB
 Downloaded:  1066 Time(s)


vars_files_both.zip
 Description:
vars files

Download
 Filename:  vars_files_both.zip
 Filesize:  785 Bytes
 Downloaded:  934 Time(s)

gene
DD-WRT Guru


Joined: 28 Dec 2007
Posts: 619

PostPosted: Tue Apr 21, 2009 14:34    Post subject: Reply with quote
frater:
I'd like to know if you made a correction to your original script post ? reading through the thread it looks like others have had the same question I have as to why the main script is producing empty restore scripts ? this is the contents of the dangerous.sh script, it should not be empty:

#!/bin/sh
#
echo "Write variables"


# Commit variables
echo "Save variables to nvram"
nvram commit

if you have not corrected YOUR script, would you mind doing so ? I'm not interested in using someone elses script where mods have been applied. I trust you and your scripts, I'm not looking for tweaked scripts. I wish people would leave your threads and scripts alone and start new threads if they want to change what you are donating to the project.

one final thought.....I'm not sure that the ISP DHCP address should be included in the restore script as the ISP assigned DHCP address may very well have been assigned to another customer thus producing IP conflicts. that would require a modem re-boot which most people would not think to do if they were trying to figure out why internet access suddenly became unstable after running your restore script later down the road.

_________________
1 WRT160N v3 - remote AP WPA2 Personal Aes dd-wrt-mini-trailed CPU OC400,
2 wrt54G v3(BCM4712 chip rev 1, corerev=7)- AP WPA2 Personal Aes dd-wrt-mini-generic CPU OC228,
1 wrt54gs v6 - remote AP WPA2 Personal Aes dd-wrt-micro CPU OC228 ,
3 WAP54g v3 - repeater, client Bridge, repeater bridge dd-wrt-micro CPU OC225,
1 NetGear WNR2000 v3 AP Atheros AR7241 ver 1 rev 1.1 (0x0101) Trailed build CPU OC360
DD-WRT usually the most current BS builds and less frequently lately EKO builds(because of new BS rules that eliminated EKO builds I used).
tcharron
DD-WRT User


Joined: 12 Aug 2007
Posts: 112

PostPosted: Tue Apr 21, 2009 14:52    Post subject: Reply with quote
The bad output may be due to having an empty line at the end of your vars_to_skip file.
gene
DD-WRT Guru


Joined: 28 Dec 2007
Posts: 619

PostPosted: Tue Apr 21, 2009 15:41    Post subject: Reply with quote
tcharron wrote:
The bad output may be due to having an empty line at the end of your vars_to_skip file.
humm, that does seem to have had an impact. now that I have output to look at in that script, I'm wondering if I was messing with fire using the all.sh script to restore everything when I should have been using the essential.sh script ? all feedback is welcome....
_________________
1 WRT160N v3 - remote AP WPA2 Personal Aes dd-wrt-mini-trailed CPU OC400,
2 wrt54G v3(BCM4712 chip rev 1, corerev=7)- AP WPA2 Personal Aes dd-wrt-mini-generic CPU OC228,
1 wrt54gs v6 - remote AP WPA2 Personal Aes dd-wrt-micro CPU OC228 ,
3 WAP54g v3 - repeater, client Bridge, repeater bridge dd-wrt-micro CPU OC225,
1 NetGear WNR2000 v3 AP Atheros AR7241 ver 1 rev 1.1 (0x0101) Trailed build CPU OC360
DD-WRT usually the most current BS builds and less frequently lately EKO builds(because of new BS rules that eliminated EKO builds I used).
tcharron
DD-WRT User


Joined: 12 Aug 2007
Posts: 112

PostPosted: Tue Apr 21, 2009 20:56    Post subject: Reply with quote
Well, restoring all.sh to different hardware could be a disaster that could brick the target box.

I found that the default settings in vars_to_skip had prevented me moving from one box to another (see my post earlier in this thread).

I really like RjG's additions to the script. I have my own vars_preferred now that includes what I need (about twice the size of his file), and I'm more confident now about moving settings from one box to another.
Goto page Previous  1, 2, 3, 4, 5 ... 22, 23, 24  Next Display posts from previous:    Page 4 of 24
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