Asterisk Backup Shell Script: Difference between revisions

From KlavoWiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 25: Line 25:
/bin/tar -rvf /tmp/$strBackupFilename var/spool/asterisk/*  
/bin/tar -rvf /tmp/$strBackupFilename var/spool/asterisk/*  
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/agi-bin/*
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/agi-bin/*
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/moh/*
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/astdb
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/astdb
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/sounds/announce
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/sounds/announce
Line 37: Line 36:
/bin/tar -rvf /tmp/$strBackupFilename opt/op_panel-0.30/op_style.cfg
/bin/tar -rvf /tmp/$strBackupFilename opt/op_panel-0.30/op_style.cfg
/bin/tar -rvf /tmp/$strBackupFilename opt/op_panel-0.30/op_server.cfg
/bin/tar -rvf /tmp/$strBackupFilename opt/op_panel-0.30/op_server.cfg
/bin/tar -rvf /tmp/$strBackupFilename usr/lib/asterisk/modules/codec_g72?-ast16*
/bin/tar -rvf /tmp/$strBackupFilename usr/lib/asterisk/modules/codec_siren*
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/licenses/*
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/licenses/*
/bin/tar -rvf /tmp/$strBackupFilename usr/sbin/fax2mail
/bin/tar -rvf /tmp/$strBackupFilename usr/sbin/fax2mail
Line 45: Line 42:
/bin/tar -rvf /tmp/$strBackupFilename etc/rc.local
/bin/tar -rvf /tmp/$strBackupFilename etc/rc.local
/bin/tar -rvf /tmp/$strBackupFilename root/$strCurDate-asterisk.sql
/bin/tar -rvf /tmp/$strBackupFilename root/$strCurDate-asterisk.sql
/bin/tar -rvf /tmp/$strBackupFilename root/$strCurDate-reverseau.sql


# Gzip tar file to reduce size
# Gzip tar file to reduce size

Revision as of 23:28, 3 May 2011

This section details the way I currently backup my Asterisk server. The script will create a tar.gz file with all the required files and then copy them to a Windows computer where I can store/archive the backups. If I ever need to restore a file or rebuild the server I can easily restore the configuration by decompressing the tar.gz file.

#!/bin/bash

# Define configuration values here
strSiteName="BackupFolder"
strBackupServer="fileserver.home.local"
strBackupFolder="sharename"
strSambaUser="username"
strSambaPass="password"
strSambaDomain="domain"

# *** DO NOT EDIT BELOW THIS LINE ***
strCurDate=$(date +%Y%m%d%H%M)
strBackupFilename="$strCurDate.tar"
strBackupPath="//$strBackupServer/$strBackupFolder"

mysqldump asteriskcdr >/root/$strCurDate-asterisk.sql
mysqldump reverseau >/root/$strCurDate-reverseau.sql

cd /
/bin/tar -cvf /tmp/$strBackupFilename etc/dahdi/*
/bin/tar -rvf /tmp/$strBackupFilename etc/asterisk/*
/bin/tar -rvf /tmp/$strBackupFilename var/spool/asterisk/* 
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/agi-bin/*
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/astdb
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/sounds/announce
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/sounds/ivr
/bin/tar -rvf /tmp/$strBackupFilename var/log/asterisk/*
/bin/tar -rvf /tmp/$strBackupFilename var/spool/cron/root
/bin/tar -rvf /tmp/$strBackupFilename var/www/html/call-back/*
/bin/tar -rvf /tmp/$strBackupFilename var/www/html/GoTalk.php
/bin/tar -rvf /tmp/$strBackupFilename opt/asteriskBackupconfig
/bin/tar -rvf /tmp/$strBackupFilename opt/op_panel-0.30/op_buttons.cfg
/bin/tar -rvf /tmp/$strBackupFilename opt/op_panel-0.30/op_style.cfg
/bin/tar -rvf /tmp/$strBackupFilename opt/op_panel-0.30/op_server.cfg
/bin/tar -rvf /tmp/$strBackupFilename var/lib/asterisk/licenses/*
/bin/tar -rvf /tmp/$strBackupFilename usr/sbin/fax2mail
/bin/tar -rvf /tmp/$strBackupFilename etc/aliases
/bin/tar -rvf /tmp/$strBackupFilename etc/logrotate.d/asterisk
/bin/tar -rvf /tmp/$strBackupFilename etc/rc.local
/bin/tar -rvf /tmp/$strBackupFilename root/$strCurDate-asterisk.sql
/bin/tar -rvf /tmp/$strBackupFilename root/$strCurDate-reverseau.sql

# Gzip tar file to reduce size
/bin/gzip /tmp/$strBackupFilename

# Make a mount point and mount the SMB server to it
/bin/mkdir /tmp/smbmountpoint
/bin/mount -t cifs -o workgroup=$strSambaDomain,username=$strSambaUser,password=$strSambaPass //$strBackupServer/$strBackupFolder /tmp/smbmountpoint

# Move the backup file into the $strSiteName folder
/bin/mv /tmp/$strBackupFilename.gz /tmp/smbmountpoint/$strSiteName/

# Clean up by unmounting mount point and deleting temporary files
/bin/umount /tmp/smbmountpoint
/bin/rmdir /tmp/smbmountpoint
/bin/rm -f /tmp/$strBackupFilename.gz

/bin/rm -f /root/*sql