Incredible Backup Enhancements

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
20,217
Reaction score
5,974
This thread is reserved for future enhancements provided by members of the PIAF community.
 
Scratch Location Option

I added some code to allow the user to define the path to use for creation of temporary files created during the backup operation. The reason I did this is because I found I did not have enough disk space on the system drive to contain the archive and the temporary files at the same time. So I needed to use another file system located on another drive as scratch area.


The backup script uses / as the path to create the temporary files in by default. I added a variable called scratchloc near the top of the script which can redefine the location used for temporary files. If the scratchloc is left empty ("") then the default will be used. In addition I reordered the creation of the tarbell to minimize the scratch size required.

The scratchloc variable can contain any valid path and is probably most useful when it points to a mnt. In my case this was a shared folder on my desktop but it could be any mounted path such as a USB Disk on Key (DOK), another drive, or a PogoPlug.

If you have plenty of space available on your system drive then it would be best to just use the default. If you see an error message like (Wrote only XXXX of YYYY bytes) then you may not have enough space available on your system drive for the backup to successfully operate; in that case you can simply use the scratchloc to point to a mounted location which has enough file space available.

Code:
#!/bin/bash
###################################################################################
# Insert the destination directory for your backups surrounded by quotes below:   #
#                                                                                 #
#backuploc="/incredible-backup"                                                   #
#backuploc="/mnt/pogoplug/WD My Book 1110/PIAF-Backup"                            #
###################################################################################
backuploc=""                      
###################################################################################
#                                                                                 #
# If you wish to use a temporary directory other than the default then            #
# insert the path to a directory to be used for creation of temporary             #
# files below between the "" below.                                               #
#                                                                                 #
# Example: scratchloc="/mnt/scratch/"                                             #
###################################################################################
scratchloc=""
#
#                               Copyright (C) 2010 Ward Mundy
#
#                    IncredibleBackup 1.0 is licensed under the GPL2 license
#
#  For a copy of license, visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
#   For additional information, contact us: http://pbxinaflash.com/about/comment.php
#
#
#
clear
echo "IncredibleBackup is free software PROVIDED AS IS subject to GPL2 license."
echo "NO WARRANTIES EXPRESS OR IMPLIED ARE PROVIDED WITH THIS SOFTWARE"
echo "INCLUDING THE IMPLIED WARRANTIES OF FITNESS FOR USE AND MERCHANTABILITY."
echo "YOU AGREE TO ASSUME ALL RISK AND TO DETERMINE SUITABILITY TO MEET YOUR NEEDS."
echo "Before continuing, read the license:"
echo "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html"
echo " "
if [ "$scratchloc" = "" ]; then
 echo "Scratch Location is the Default /"
 scratchloc="/"
else
 # Add the / if it is missing
 if [ `echo "$scratchloc" | grep "[^/]$"` ]; then scratchloc="$scratchloc/"; fi
 echo "Incredible Backup Scratch Path: $scratchloc"
fi
echo " "
#
if [ ! -d "$scratchloc" ] && [ ! "$scratchloc" = "" ]; then
 echo " "
 echo "Scratch location not available"
 echo "Make sure the scratchloc string is empty (i.e scratchloc='') to use default path or"
 echo "Check that your desired path exists and a / is at the end of the scratchloc string"
 echo "Make sure if your using a mnt share that it is mounted!"
 echo " "
 echo "Then run the script again."
 echo " "
 echo " "
 exit
fi
#
if [ -z "$backuploc" ]; then
 echo " "
 echo "Before using IncredibleBackup, please enter"
 echo "the target directory for your backups by editing"
 echo "this script: nano -w incrediblebackup"
 echo "If storing your backups on this server, do NOT"
 echo "use /root or /var/www directory trees for storage!"
 echo "Preferably create a new directory, for example:"
 echo "mkdir /incredible-backup"
 echo "Then run the script again."
 echo " "
 echo " "
 exit
elif [ ! -d "$backuploc" ]; then
 echo " "
 echo "Backup destination ($backuploc) is NOT on line."
 echo "Please correct the problem and try again."
 echo " "
 echo " "                                            
 exit
fi
tstamp=`date +%s`
#
# Comment out the following line if you want to use this backup in a cron job.
# Only comment out the following lines after you agree to the terms of the GPL2 license.
echo "Incredible Backup Destination: $backuploc/$tstamp.tgz"
echo " "
read -p "To proceed at your own risk and agree to license, press Enter. Otherwise Ctrl-C."
#

clear
echo "Incredible Backup starting..."

cd /root
echo "Backing up current FreePBX distro version to /root..."
fpbxver=`sed -n 4p /var/www/html/admin/modules/framework/module.xml | cut -c11-15`
#wget -N http://mirror.freepbx.org/freepbx-2.5.1.tar.gz
#wget -N http://mirror.freepbx.org/freepbx-2.5.2.tar.gz
#wget -N http://mirror.freepbx.org/freepbx-2.6.0.tar.gz
#wget -N http://mirror.freepbx.org/freepbx-2.7.0.tar.gz
wget -N http://mirror.freepbx.org/freepbx-$fpbxver.tar.gz

echo "Stopping services..."
amportal stop
service mysqld stop
service httpd stop

cd $scratchloc
echo "Creating tarball..."
tar -cf $tstamp.tar /var/www/html /var/lib/asterisk /var/lib/mysql /root /etc/asterisk /tftpboot
tar -uf $tstamp.tar /etc/pbx /etc/crontab /etc/sudoers /etc/amportal.conf /etc/odbc.ini /etc/odbcinst.ini
tar -uf $tstamp.tar /var/lib/asterisk/sounds/tts /var/lib/asterisk/sounds/custom /var/spool/asterisk
tar -cf $tstamp.1.tar /etc/hosts /etc/resolv.conf /etc/sysconfig/network-scripts/ifcfg* /etc/sysconfig/iptables /etc/sysconfig/network
tar -uf $tstamp.tar $tstamp.1.tar
rm $tstamp.1.tar
tar -cf $tstamp.2.tar /etc/mail
tar -uf $tstamp.tar $tstamp.2.tar
rm $tstamp.2.tar
tar -cf $tstamp.3.tar /usr/local/bin /usr/local/sbin /usr/src
tar -uf $tstamp.3.tar /usr/sbin/fxotune /usr/sbin/asterisk /usr/sbin/astgenkey /usr/sbin/autosupport /usr/sbin/rasterisk /usr/sbin/aelparse /usr/sbin/astman /usr/sbin/muted /usr/sbin/smsg /usr/sbin/stereorize /usr/sbin/streamplayer /usr/sbin/amportal /usr/sbin/safe_asterisk /usr/sbin/fpga_load /usr/sbin/genzaptelconf /usr/sbin/lszaptel /usr/sbin/xpp_blink /usr/sbin/xpp_sync /usr/sbin/zapconf /usr/sbin/zaptel_hardware /usr/sbin/zt_registration
tar -uf $tstamp.3.tar /usr/sbin/astribank* /usr/sbin/dahdi* /usr/sbin/lsdahdi /usr/sbin/sethdlc /usr/sbin/twinstar 
tar -uf $tstamp.tar $tstamp.3.tar
rm $tstamp.3.tar

echo "Starting services..."
service httpd restart
service mysqld restart
amportal start

echo "Compressing tarball..."
gzip $tstamp.tar
echo "Done."
echo "Moving $tstamp.tgz backup to $backuploc directory..."
mv $tstamp.tar.gz "$backuploc/$tstamp.tgz"
echo " "
echo " "
echo "Thank you for using PBX in a Flash and the Incredible PBX."
echo "Incredible Backup is done."
 

Members online

No members online now.

Forum statistics

Threads
26,687
Messages
174,410
Members
20,257
Latest member
Dempan
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Back
Top