OpenWrt backup script

If you don’t already, you should backup your router configs on a regular basis. I’ve written a small Ash script to backup the /etc directory of my OpenWrt router. This is not the same as a firmware backup, or a restorable backup made by the sysupgrade tool. This backup is meant to be a way to keep a copy of your flat-files, nothing more. If you need to restore them, you’ll need to install OpenWrt first, then restore the files manually.

The generate_backups.ksh script backs up the list of installed packages and the /etc directory using tar. The script is over at GitHub, but also pasted below (check GitHub first).


#This script should be run as root, since it's accessing /etc.

#Set variables
HOSTNAME=`uci get system.@system[0].hostname`

#Make backup directory if it doesn't exist
mkdir -p ${BACKUP_FOLDER}

#Remove all old backups
rm /backup/backup/*.gz

#Backup installed package list to /etc
opkg list-installed | cut -f 1 -d ' ' > /etc/packages.txt

#Backup /etc
tar -czf ${BACKUP_FOLDER}/${HOSTNAME}_$(date +%Y%m%d_%H%M)_etc.tar.gz ${CONFIG_FOLDER} >/dev/null 2>&1




Leave a Comment