quinta-feira, agosto 21, 2014

DD-WRT Forum :: View topic - Backup settings and restore them to even different hardware.

DD-WRT Forum :: View topic - Backup settings and restore them to even different hardware.

Very usefull



When DD-WRT does a backup of the settings this is done in a binary way. Even if no variables have changed and the hardware has not changed, it is not totally safe to restore this binary backup on another version.



I'm saving these variables to a script. This was not my idea, but the other implementation on this forum was saving more than it should.



This script also creates some variables that don't really exist. I previously wrote a script that was able to avoid this, but it had a terrible speed-impact. The variables it creates (makes up) comes from data containing a "=". This really is not a problem.



I'm deliberately skipping some variables that contain hardware-specific data. This way it is safe to restore these settings on different hardware.

After an upgrade you can run this restore-script and be up and running in no time.



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=/opt/var/backups

TO_ALL=${FOLDER}/${MAC}.${DATE}.all.sh

TO_INCLUDE=${FOLDER}/${MAC}.${DATE}.essential.sh

TO_EXCLUDE=${FOLDER}/${MAC}.${DATE}.dangerous.sh

FTPS=ftp://192.168.10.210/backups

USERPASS=user:pass



nvram show 2>/dev/null | egrep '^[a-zA-Z].*=' | awk -F= '{print $1}' | grep -v "[ /+<>,:;]" | sort -u >/tmp/all_vars



#

echo -e "#!/bin/sh\n#\necho \"Write variables\"\n" | tee -i ${TO_EXCLUDE} | tee -i  ${TO_ALL} > ${TO_INCLUDE}



cat /tmp/all_vars | while read var

do

  if echo ${var} | grep -q -f "${CUR_DIR}/vars_to_skip" ; then

    bfile=$TO_EXCLUDE

  else

    bfile=$TO_INCLUDE

  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 /tmp/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}



tar cpf - -C / "${TO_INCLUDE}" 2>/dev/null | /opt/bin/gzip -c |  /opt/bin/curl -s -u ${USERPASS} "${FTPS}/${FILE}.essential.sh.tgz" -T -

tar cpf - -C / "${TO_EXCLUDE}" 2>/dev/null | /opt/bin/gzip -c |  /opt/bin/curl -s -u ${USERPASS} "${FTPS}/${FILE}.dangerous.sh.tgz" -T -

tar cpf - -C / "${TO_ALL}" 2>/dev/null | /opt/bin/gzip -c |  /opt/bin/curl -s -u ${USERPASS} "${FTPS}/${FILE}.all.sh.tgz" -T -



vars_to_skip

Code:

DD_BOARD

^board

browser_method

^cfe

ct_modules

custom_shutdown_command

^def_

^default_

dist_type

dl_ram_addr

early_startup_command

^et0

^et1

^ezc

generate_key

gozila_action

gpio

^hardware

^is_

^kernel_

lan_default

^lan_hw

^lan_ifname

landevs

manual_boot_nv

misc_io_mode

need_commit

^os_

overclocking

pa0maxpwr

phyid_num

pmon_ver

pppd_pppifname

pppoe_ifname

pppoe_wan_ifname

primary_ifname

probe_blacklist

regulation_domain

rescue

reset_

scratch

sdram

^sh_

^skip

sshd_dss_host_key

sshd_rsa_host_key

startup_command

^wan_default

^wan_hw

^wan_if

^wan_vport

^wandevs

web_hook_libraries

^wifi_

wl0.1_hwaddr

wl0.2_hwaddr

wl0.3_hwaddr

wl0_hwaddr

wl0_ifname

wl0_radioids

wl_hwaddr

wl_ifname

^wlan_

Nenhum comentário: