Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

Intro

This script is meant to back up Audiocodes gateways that are being managed manually (without using sipXecs)

Prerequisites

You must have python and curl installed and create the file: /etc/cron.daily/current_devices.csv

CSV format

The CSV format that is used to determine the gateway is as follows:

IP address

Descriptive Gateway Name

username

password

Device Location

192.168.1.4

Tech-Services-MP114-FXO

admin

password

Information Technology

So the csv would look like:

current_devices.csv
192.168.1.4,Tech-Services-MP114-FXO,admin,password,Information Technology

The Script

voip_backup.py
#!/usr/bin/python

import csv
import string
import os
import sys
import time
import datetime

today = datetime.date.today()
csv_filename = '/etc/cron.daily/current_devices.csv'
backup_dir = '/var/sipxdata/backup/external'
datecode = str(today.strftime('%Y%m%d'))

csv_dump = []
reader = csv.reader(open(csv_filename),delimiter=',')
for row in reader:
	csv_attrib={}
	csv_attrib["IP"] = row[0]
	csv_attrib["name"] = row[1]
	csv_attrib["username"] = row[2]
	csv_attrib["password"] = row[3]
	csv_attrib["location"] = row[4]
	csv_dump.append(csv_attrib)
	
r = 1

while r < len(csv_dump):
	if (os.path.exists(backup_dir + '/' + datecode + '/' + csv_dump[r]["location"]) == False):
		print "Directory doesn't exist....creating..."
		os.makedirs(backup_dir + '/' + datecode + '/' + csv_dump[r]["location"], 0755)
	if (os.path.isfile(backup_dir + '/' + datecode + '/' + csv_dump[r]["location"] + '/' + csv_dump[r]["name"] + '.ini') == True):
		print "File exists, removing..."
		os.remove(backup_dir + '/' + datecode + '/' + csv_dump[r]["location"] + '/' + csv_dump[r]["name"] + '.ini')
	os.system('curl --digest -C - -o ' + backup_dir + '/' + datecode + '/' + csv_dump[r]["location"] + '/' + csv_dump[r]["name"] + '.ini http://' + csv_dump[r]["username"] + ':' + csv_dump[r]["password"] + '@' + csv_dump[r]["IP"] + '/FS/BOARD.ini')
	r = r + 1

The code is attached here: voip_backup.py

If you want to do a daily backup simply place this script and the CSV file into /etc/cron.daily and make the script executable:

chmod +x /etc/cron.daily/voip_backup.py
  • No labels