A new version is available please refer to this tutorial.
The information bellow pertains to the old version of the script.
Here is the link to the doc. It contains the most recent changes
To set your "Main USB Disk" use this by putting it in your USB "Run After Mounting" script box under [USB & NAS -> USB Support].
nvram set usb_disk_main=/tmp/mnt/USB_DISK
Put script below in the “Administraton-> Scripts” inside the [Init] Box. Then Click [Save]
You will have to reboot the router for this script to take effect.
# Create Scripts DIR
DIR="/tmp/scripts"
[ -d "$DIR" ] && echo "$DIR exists" || echo "creating $DIR/" && mkdir -p "$DIR"
echo '
# Flash LED Script v1.1 2010/10/22
# Written By: Austin Saint Aubin
# flashLED.sh [LEDNAME] [SleepTime] [NumberOfTimes] [EndState]
# sh /tmp/scripts/flashLED.sh aoss 12500 5 off
i=1
while [ $i -le $3 ]; do
logger -s -t FlashLED "LED Flash Iteration" $i
usleep $2
led $1 on
usleep $2
led $1 off
let i++
done
led $1 $4
' > /tmp/scripts/flashLED.sh
Put script below in the “Tools -> System” inside the Box. Then Click [Execute]
Use “sh $(nvram get usb_disk_main)/Tomato/backupToUSB.sh” to run script.
echo '# Tomato Backup Script 2011/02/20 - v7.5 - USB DRIVE VERSION
# Written By: Austin Saint Aubin
# Link to Script: https://docs.google.com/document/d/1gxLsOR-WawC7tYzWt_zRexa5N3EzwlWy5QONzJO8YTI/edit?hl=en&authkey=CLzHkp4C#
#Use "nvram set usb_disk_main=/tmp/mnt/USB_DISK" to set a global main usb disk for all scripts.
USBDrvDIR=$(nvram get usb_disk_main)
ComDIR="Tomato"
NumOfBackupsToKeep=32
backupToUSB()
{
logItHead 1 "***[Running Backup]***" $(date +%Y-%m-%d_%H%M%S)
logIt "$(nvram get os_version)"
if [ -d "$USBDrvDIR" ]; then
led aoss on
logItHead 1 "USB Drive is Pressent" $USBDrvDIR
checkFolder "$USBDrvDIR/$ComDIR"
# This is where all the magic happens, change the backupThisUp lines as you like.
backupThisUp web RouterConfiguration Configurations tomato_v128_mb60ee6 $NumOfBackupsToKeep cfg cfg/tomato_v128_mb60ee6.cfg
backupThisUp web SysLog SysLogs syslog $NumOfBackupsToKeep txt logs/syslog.txt
backupThisUp web WebDomains WebUsage WebDomains $NumOfBackupsToKeep txt webmon_recent_domains
backupThisUp web WebSearches WebUsage WebSearches $NumOfBackupsToKeep txt webmon_recent_searches
backupThisUp sh SysInfo SysInfo SysInfo $NumOfBackupsToKeep txt sysinfo
backupThisUp nvram NVRam NVRam NVRam 64 txt
#backupThisUp ark Optware Optware/Archive Optware $NumOfBackupsToKeep tar.gz czf /opt
backupThisUp sh ScriptsBackup Scripts-Backup Transfer-Log 1 txt "cp /tmp/*.sh $USBDrvDIR/$ComDIR/Scripts-Backup"
wget -O - "http://admin:$(nvram get http_passwd)@$(nvram get lan_ipaddr)/bwm-daily.asp" >> /dev/null
backupThisUp web BandwidthUsage BandwidthUsage/MoreBackups tomato_rstats_c03f0eb60ee6 $NumOfBackupsToKeep gz bwm/tomato_rstats_c03f0eb60ee6.gz
sleep 1
rstats
logItHead 3
#cp /tmp/scripts/backupToUSB.sh "$USBDrvDIR/$ComDIR"
led aoss off
(sh /tmp/scripts/flashLED.sh aoss 500000 3 off) & logIt "***[Backup Completed]*** $(date +%Y-%m-%d_%H%M%S)"
#exit 0
else
(sh /tmp/scripts/flashLED.sh aoss 1000000 30 on) & logItHead 9 $USBDrvDIR "not found! No FlashDrive"
#exit 1
fi
}
backupThisUp()
{
logItHead 2 "[Backuping up ($2]"
checkFolder "$USBDrvDIR/$ComDIR/$3"
logItHead 3
cleanupFiles "$USBDrvDIR/$ComDIR/$3/" $4"*."$6 $5
logItHead 3
cd $USBDrvDIR/$ComDIR/$3/
if [ $1 == web ]; then
logIt "Downloading $2"
wget "http://admin:$(nvram get http_passwd)@$(nvram get lan_ipaddr)/"$7"?_http_id=$(nvram get http_id)" -O $4_$(date +%Y-%m-%d_%H%M%S).$6
elif [ $1 == sh ]; then
logIt "Getting $2"
$7 > $4_$(date +%Y-%m-%d_%H%M%S).$6
elif [ $1 == ark ]; then
logIt "Archiving $2 at" $8
tar $7 $4_$(date +%Y-%m-%d_%H%M%S).$6 $8
elif [ $1 == nvram ]; then
logIt "Getting $2"
nvram export --quote | sort | awk '\''{print "\#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-\nnvram set " $0}'\'' | sed '\''s/\\n/\n/g'\'' | sed '\''s/\$/\\$/g'\'' > $4_$(date +%Y-%m-%d_%H%M%S).$6
else
logIt "/!\\ backupThisUp Error /!\\"
fi
}
cleanupFiles()
{
cd $1
logIt "Running Cleanup for $1"
logIt "Num of Backups to keep: $3"
NumOFiles=$(find $2 | wc -l);
i=$NumOFiles
ls -1 $2 | while read file
do
logIt "Checking($i): $file"
if [ $NumOFiles -gt $3 ]; then
logIt "[$NumOFiles > $3 ] Deleting #$i: $file"
rm -f $file
NumOFiles=$(find $2 | wc -l);
fi
let i--
done
}
logItHead()
{
if [ $1 == 1 ]; then
logIt "***===============*****===============***"
logIt $2 $3
elif [ $1 == 2 ]; then
logIt "========================================="
logIt $2
elif [ $1 == 3 ]; then
logIt "~---------------------------------------~"
else
logIt "/!\\" $2 "/!\\"
fi
}
logIt()
{
echo "$@"
logger -t BackupToUSB "$@"
}
checkFolder()
{
[ -d "$@" ] && logIt "$@ folder exists" || (logIt "$@ folder NOT exists, Creating Dir: $@/"; mkdir -p "$@")
}
backupToUSB > $USBDrvDIR/$ComDIR/backupToUSB_Log.txt' > "$(nvram get usb_disk_main)/Tomato/backupToUSB.sh"
Here is some nice output.
=========================================
***[Running Backup]*** 2010-10-14_000003
=========================================
FlashDrive is Pressent /tmp/mnt/300GB_NTFS
Tomato folder exists
= = = = = = = = = = = = = = = = = = = = =
[Backuping up (RouterConfiguration]
Configurations folder exists
- - - - - - - - - - - - - - - - - - - - -
Running Cleanup for /tmp/mnt/300GB_NTFS/Tomato/Configurations/
Num of Backups to keep: 7
Checking(2): tomato_v128_mb60ee6_2010-10-13_220700.cfg
Checking(1): tomato_v128_mb60ee6_2010-10-13_220959.cfg
- - - - - - - - - - - - - - - - - - - - -
Downloading RouterConfiguration
= = = = = = = = = = = = = = = = = = = = =
[Backuping up (SysLog]
SysLogs folder exists
- - - - - - - - - - - - - - - - - - - - -
Running Cleanup for /tmp/mnt/300GB_NTFS/Tomato/SysLogs/
Num of Backups to keep: 7
Checking(2): syslog_2010-10-13_220703.txt
Checking(1): syslog_2010-10-13_221000.txt
- - - - - - - - - - - - - - - - - - - - -
Downloading SysLog
= = = = = = = = = = = = = = = = = = = = =
[Backuping up (WebDomains]
WebUsage folder exists
- - - - - - - - - - - - - - - - - - - - -
Running Cleanup for /tmp/mnt/300GB_NTFS/Tomato/WebUsage/
Num of Backups to keep: 7
Checking(2): WebDomains_2010-10-13_220705.txt
Checking(1): WebDomains_2010-10-13_221002.txt
- - - - - - - - - - - - - - - - - - - - -
Downloading WebDomains
= = = = = = = = = = = = = = = = = = = = =
[Backuping up (WebSearches]
WebUsage folder exists
- - - - - - - - - - - - - - - - - - - - -
Running Cleanup for /tmp/mnt/300GB_NTFS/Tomato/WebUsage/
Num of Backups to keep: 7
Checking(2): WebSearches_2010-10-13_220706.txt
Checking(1): WebSearches_2010-10-13_221003.txt
- - - - - - - - - - - - - - - - - - - - -
Downloading WebSearches
= = = = = = = = = = = = = = = = = = = = =
[Backuping up (SysInfo]
SysInfo folder exists
- - - - - - - - - - - - - - - - - - - - -
Running Cleanup for /tmp/mnt/300GB_NTFS/Tomato/SysInfo/
Num of Backups to keep: 7
Checking(2): SysInfo_2010-10-13_220707.txt
Checking(1): SysInfo_2010-10-13_221004.txt
- - - - - - - - - - - - - - - - - - - - -
Getting SysInfo
= = = = = = = = = = = = = = = = = = = = =
[Backuping up (BandwidthUsage]
BandwidthUsage/MoreBackups folder exists
- - - - - - - - - - - - - - - - - - - - -
Running Cleanup for /tmp/mnt/300GB_NTFS/Tomato/BandwidthUsage/MoreBackups/
Num of Backups to keep: 7
Checking(1): tomato_rstats_c03f0eb60ee6_2010-10-13_220713.gz
- - - - - - - - - - - - - - - - - - - - -
Downloading BandwidthUsage
rstats
Copyright (C) 2006-2009 Jonathan Zarate
***[Backup Completed]*** 2010-10-14_000038
LED Flash Iteration 1
LED Flash Iteration 2
LED Flash Iteration 3