Posted: March 18th, 2011 | Author: Gregg | Filed under: Linux, Tech | Tags: asus, backup, bash, cron, Linux, polarcloud, router, script, tomato, tomato cron backup, tomato router backup | 2 Comments »
I recently was given the task to automate the backups of several remote routers that we manage that run tomato firmware.
Here is the Tomato developer’s site: www.polarcloud.com/tomato
The main goals were:
- To use https
- To be automated (Cron)’d later
- To scale from 1 to 1XXX routers
I tested it on Tomato Firmware 1.28 using my ASUS RT-N16 router, but it should work for any Tomato-firmware router.
There will be some slight modifications to run in cron, but let me know and I’ll be glad to help.
Download the .zip file here: tomatobackup1405
Extract the file so the full path will be /root/tomatobackup1405
Read the README inside the folder
chmod +x tomatobackup1405.sh
Add your hosts to the tomatobackup1405_hosts.cfg file
Run it!
If successful, you will see a subfolder with the date YYYYMMDD and the file with CoName-tomato_v_.cfg
If there are connection problems, you’ll see an error message.
EDIT: There was a python rewrite by Sam@orgraphone.org
Feel free to check it out here
Let me know if you have any thoughts or suggestions.
-Gregg
Posted: April 27th, 2009 | Author: Gregg | Filed under: Asterisk VoIP, Linux, Tech, Uncategorized | Tags: asterisk backup, Asterisk VoIP, at backup asterisk, atd, automated asterisk backup, automated backup, automatic ftp connection, backup asterisk, backup asterisk files, backup asterisk script, backup etc/asterisk, bash, centos, connect ftp bash, cron, cron backup, cron backup asterisk, ftp bash, gz, gz asterisk, interactive backup, Linux, safe1405, tar, tar asterisk, voip | 6 Comments »
Summary:
Safe1405 is a bash script that will backup the popular Asterisk directories and place them in a tar.gz file. The script can be used in 1 of 2 modes.
The first mode is interactive, with a menu to choose:
- Backup Everything (/etc/asterisk, Voicemail, Recordings, Sounds)
- Just VM
- Just Recordings
- Just Sounds
After the file is created, it will prompt to upload to a remote FTP server.
The second mode is silent, and is best suited for automated execution via cron or at.
Just enable the UNATTENDED and PUT_FTP variables by setting them to “1″. You can directly edit the paths to each directory if yours are non-standard.
The script can be directly downloaded here: Safe1405 Download Link
Code:
#!/bin/bash
# Safe1405
# Author: Gregg Hansen - www.thiscoolsite.com
# Safely tar and gzip Asterisk files
# Version 1.0 20090427
#-Backs up all important Asterisk files - Tar/Gz
#-Choose the file name, or Date by default
#-GUI-like. Able to be silent for cron, or interactive
#EDIT the below ABSOLUTE paths to match your directory structure:
VAR_LIB="/var/lib/asterisk"
ETC_AST="/etc/asterisk"
VM="/var/spool/asterisk/voicemail"
MON="/var/spool/asterisk/monitor"
#Date Var
FILEDATE="$(date +%Y%m%d)"
#Your ServerName
#Filename is FILEDATE-SERVERNAME.tar.gz
SERVERNAME="Chicago-Ast01"
#Enable unattended mode/Remote FTP put (useful for Cron):
# Backup of /etc/asterisk ONLY (default)
# 1 = On, 0 = Off
UNATTENDED="0"
PUT_FTP="0"
#FTP Credentials
FTP_IP="127.0.0.1"
FTP_USER="admin"
FTP_PASS="secret"
###--START CODE---###
### Interactive Mode Functions ###
prompt()
{
cat <<EOF
Safe1405 Backup
1) Everything
2) /etc/asterisk
3) Voicemail
4) Recordings
5) Sounds
Q) Quit
EOF
echo -n "Prompt> "
read INPUT
case $INPUT in
1) everything;;
2) etc-ast;;
3) vm;;
4) recordings;;
5) sounds;;
q) exit;;
Q) exit;;
esac
}
everything()
{
FILENAME="$FILEDATE-$SERVERNAME-FULL.tar.gz"
tar cfvz $FILENAME $ETC_AST $VM $MON $VAR_LIB
ftpprompt
}
etc-ast()
{
FILENAME="$FILEDATE-$SERVERNAME-ETC_AST.tar.gz"
tar cfvz $FILENAME $ETC_AST
ftpprompt
}
vm()
{
FILENAME="$FILEDATE-$SERVERNAME-VM.tar.gz"
tar cfvz $FILENAME $VM
ftpprompt
}
recordings()
{
FILENAME="$FILEDATE-$SERVERNAME-REC.tar.gz"
tar cfvz $FILENAME $MON
ftpprompt
}
sounds()
{
FILENAME="$FILEDATE-$SERVERNAME-SOUNDS.tar.gz"
tar cfvz $FILENAME $VAR_LIB
ftpprompt
}
ftpprompt()
{
echo -en "Upload $FILENAME to FTP? (y or n) "
read INPUT
if [ "$INPUT" == "y" ]; then
quietftp
fi
}
### Unattended Mode Functions ###
silent()
{
tar cfvz $FILEDATE-$SERVERNAME-ETC-AST.tar.gz $ETC_AST ##Uncomment##$VM #$MON #$VAR_LIB
FILENAME="$FILEDATE-$SERVERNAME-ETC-AST.tar.gz"
}
quietftp()
{
ftp -ivn <<EOF
open $FTP_IP
user $FTP_USER $FTP_PASS
binary
put $FILENAME
bye
EOF
}
#### Start Program Flow ###
clear
#Unattended Function Call(s)
if [ "$UNATTENDED" == "1" ]; then
silent
if [ "$PUT_FTP" == "1" ]; then
quietftp
exit
fi
exit
fi
#Interactive Function Calls
prompt
exit
###–END CODE—###
Leave a comment if you have questions/suggestions or would like help setting up the script.
-Gregg