Created
October 25, 2010 08:00
-
-
Save dz0ny/644575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo ' | |
# Tomato Backup Script 2010/10/24 - v6.0 - FULL VERSION | |
# Written By: Austin Saint Aubin | |
#Use "nvram set usb_disk_main=/tmp/mnt/USB_DISK" to set a global main usb disk for all scripts. | |
FlashDrvDIR=$(nvram get usb_disk_main) | |
ComDIR="Tomato" | |
NumOfBackupsToKeep=28 | |
backupToUSB() | |
{ | |
logItHead 1 "***[Running Backup]***" `date +%Y-%m-%d_%H%M%S` | |
if [ -d "$FlashDrvDIR" ]; then | |
led aoss on | |
logItHead 1 "FlashDrive is Pressent" $FlashDrvDIR | |
checkFolder "$FlashDrvDIR/$ComDIR" | |
# This is where alll 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 sh NVRam NVRam NVRam $NumOfBackupsToKeep txt "nvram show" | |
#backupThisUp ark Optware Optware Optware $NumOfBackupsToKeep tar.gz czf /opt | |
backupThisUp sh ScriptsBackup Scripts-Backup Transfer-Log 1 txt "cp /tmp/*.sh $FlashDrvDIR/$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 | |
nvram get script_init > $FlashDrvDIR/$ComDIR/backupToUSB.sh | |
led aoss off | |
(sh /tmp/home/root/flashLED.sh aoss 500000 3 off) & logIt "***[Backup Completed]*** `date +%Y-%m-%d_%H%M%S`" | |
else | |
(sh /tmp/home/root/flashLED.sh aoss 1000000 30 on) & logItHead 9 $FlashDrvDIR "not found! No FlashDrive" | |
fi | |
} | |
backupThisUp() | |
{ | |
logItHead 2 "[Backuping up ($2]" | |
checkFolder "$FlashDrvDIR/$ComDIR/$3" | |
logItHead 3 | |
cleanupFiles "$FlashDrvDIR/$ComDIR/$3/" $4"*."$6 $5 | |
logItHead 3 | |
cd $FlashDrvDIR/$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 | |
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 "$1" ] && logIt "$1 folder exists" || logIt "$1 folder NOT exists, Creating Dir: $1/" && mkdir -p "$1" | |
} | |
backupToUSB > $FlashDrvDIR/$ComDIR/backupToUSB_Log.txt | |
' > /tmp/home/root/backupToUSB.sh | |
# sh /tmp/home/root/backupToUSB.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment