Asterisk Backup Shell Script: Difference between revisions

From KlavoWiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 2: Line 2:


<pre>
<pre>
strCurDate=$(date +%Y%m%d-%H%M)
#!/bin/bash


mysqldump asterisk -p"mypassword" >/root/$strCurDate-asterisk.sql
# Define configuration values here
strPublicIf="eth0"
strSiteName="Asterisk"
strBackupServer="myfileserver.home.local"
strBackupFolder="Backups"
strSambaUser="username"
strSambaPass="password"
strSambaDomain="domain"


zip -r /root/$strCurDate /etc/dahdi/*
# *** DO NOT EDIT BELOW THIS LINE ***
zip -r /root/$strCurDate /etc/asterisk/*
strCurDate=$(date +%Y%m%d%H%M)
zip -r /root/$strCurDate /var/spool/asterisk/*
strBackupFilename="$strCurDate.tar"
zip -r /root/$strCurDate /var/lib/asterisk/agi-bin/*
strBackupPath="//$strBackupServer/$strBackupFolder"
zip -r /root/$strCurDate /var/lib/asterisk/ivr/*
strCheckNet=$(/sbin/ifconfig $strPublicIf | /bin/grep -i inet)
zip -r /root/$strCurDate /var/lib/asterisk/moh/*
intCheckNetLength=${#strCheckNet}
zip    /root/$strCurDate /var/lib/asterisk/astdb
zip    /root/$strCurDate /var/lib/asterisk/sounds/announce
zip    /root/$strCurDate /var/lib/asterisk/sounds/ivr
zip    /root/$strCurDate /var/lib/asterisk/sounds/au
zip -r /root/$strCurDate /var/log/asterisk/*
zip -r /root/$strCurDate /var/www/html/*
zip -r /root/$strCurDate /usr/src/op_panel-0.29/*
zip    /root/$strCurDate /usr/lib/asterisk/modules/*
zip    /root/$strCurDate /root/$strCurDate-asterisk.sql
zip    /root/$strCurDate /opt/lumenvox/licenseserver/bin/*.bts


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


rm -f /root/$strCurDate-asterisk.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/moh/*
/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/*
/bin/tar -rvf /tmp/$strBackupFilename opt/*
/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 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


# Make temporary mount point
# 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/mkdir /tmp/smbmountpoint
/bin/mount -t smbfs -o workgroup=WORKGROUP,username=accountname,password=mypassword //pc.mycomputer.com/c$ /tmp/smbmountpoint
/bin/mount -t cifs -o workgroup=$strSambaDomain,username=$strSambaUser,password=$strSambaPass //$strBackupServer/$strBackupFolder /tmp/smbmountpoint
 
 
#strCurDate=$(date +%Y%m%d)
 
mkdir -p /tmp/smbmountpoint/Backup/Asterisk


# Move the backup file into the $strSiteName folder
# Move the backup file into the $strSiteName folder
/bin/mv /root/*.zip /tmp/smbmountpoint/Backup/Asterisk/
/bin/mv /tmp/$strBackupFilename.gz /tmp/smbmountpoint/$strSiteName/


# Clean up by unmounting mount point and deleting temporary files
# Clean up by unmounting mount point and deleting temporary files
/bin/umount /tmp/smbmountpoint
/bin/umount /tmp/smbmountpoint
/bin/rmdir /tmp/smbmountpoint
/bin/rmdir /tmp/smbmountpoint
/bin/rm -f /tmp/$strBackupFilename.gz
/bin/rm -f /root/$strCurDate-asterisk.sql
</pre>
</pre>


[[Category : Asterisk]]
[[Category : Asterisk]]

Revision as of 10:45, 7 July 2010

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
strPublicIf="eth0"
strSiteName="Asterisk"
strBackupServer="myfileserver.home.local"
strBackupFolder="Backups"
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"
strCheckNet=$(/sbin/ifconfig $strPublicIf | /bin/grep -i inet)
intCheckNetLength=${#strCheckNet}

mysqldump asteriskcdr >/root/$strCurDate-asterisk.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/moh/*
/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/*
/bin/tar -rvf /tmp/$strBackupFilename opt/*
/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 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

# 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/$strCurDate-asterisk.sql