Asterisk Backup Shell Script: Difference between revisions

From KlavoWiki
Jump to navigationJump to search
No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
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.
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.


'''Prerequisite'''
<pre>
<pre>
strCurDate=$(date +%Y%m%d-%H%M)
yum install samba-client cifs-utils
</pre>


mysqldump asterisk -p"mypassword"  >/root/$strCurDate-asterisk.sql
<pre>
#!/bin/bash


zip    /root/$strCurDate /etc/zaptel.conf
# Define configuration values here
zip -r /root/$strCurDate /etc/asterisk/*
strSiteName="BackupFolder"
zip -r /root/$strCurDate /var/spool/asterisk/*
strBackupServer="fileserver.home.local"
zip -r /root/$strCurDate /var/lib/asterisk/agi-bin/*
strBackupFolder="sharename"
zip -r /root/$strCurDate /var/lib/asterisk/ivr/*
strSambaUser="username"
zip -r /root/$strCurDate /var/lib/asterisk/moh/*
strSambaPass="password"
zip    /root/$strCurDate /var/lib/asterisk/astdb
strSambaDomain="domain"
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


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


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


# Make temporary mount point
cd /
/bin/mkdir /tmp/smbmountpoint
/bin/tar -cvf /tmp/$strBackupFilename etc/dahdi/*
/bin/mount -t smbfs -o workgroup=WORKGROUP,username=accountname,password=mypassword //pc.mycomputer.com/c$ /tmp/smbmountpoint
/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/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


#strCurDate=$(date +%Y%m%d)
# Make a mount point and mount the SMB server to it
 
/bin/mkdir /tmp/smbmountpoint
mkdir -p /tmp/smbmountpoint/Backup/Asterisk
/bin/mount -t cifs -o workgroup=$strSambaDomain,username=$strSambaUser,password=$strSambaPass //$strBackupServer/$strBackupFolder /tmp/smbmountpoint


# 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/*sql
</pre>
'''NOTE''': For the script to connect to a Windows computer you must have the [[samba-client]] and cifs-utils install.
== Raspberry Pi Image Backup ==
<pre>
pacman -S --no-confirm smbclient cifs-utils
</pre>
<pre>
mkdir /tmp/foldername
strCurDate=$(date +%Y\-%m\-%d\ \(%H%M\))
mount -t cifs -o workgroup=workgroupname,username=username,password=password //192.168.13.11/asterisk /tmp/foldername
dd if=/dev/mmcblk0 of="/tmp/foldername/$strCurDate-rpi.img" bs=1M
umount /tmp/foldername
rm -rf /tmp/foldername/
</pre>
</pre>


[[Category : Asterisk]]
[[Category : Asterisk]] [[Category : Raspberry Pi]]

Latest revision as of 06:23, 4 June 2013

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.

Prerequisite

yum install samba-client cifs-utils 
#!/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/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

NOTE: For the script to connect to a Windows computer you must have the samba-client and cifs-utils install.

Raspberry Pi Image Backup

pacman -S --no-confirm smbclient cifs-utils
mkdir /tmp/foldername

strCurDate=$(date +%Y\-%m\-%d\ \(%H%M\))

mount -t cifs -o workgroup=workgroupname,username=username,password=password //192.168.13.11/asterisk /tmp/foldername
dd if=/dev/mmcblk0 of="/tmp/foldername/$strCurDate-rpi.img" bs=1M
umount /tmp/foldername
rm -rf /tmp/foldername/