#!/bin/bash
#***************************************#
#*****http://alexeyka.zantsev.com/******#
#***************************************#
BACKUP_DIR=/home/user/PBX_BACKUPS
TAR="/bin/tar -czf"
DATE=$(date +%Y-%m-%d)
CDRDAY=$(date +%d)
SQLDUMP="/usr/bin/mysqldump"
SRVNAME=pbx_
#------------------------------------------------
# function for backup routine
bkuper ()
{
# 1. cd to dir
cd $BACKUP_DIR
mkdir BACKUP
# 2. copy mission-critical shit
for i in /etc/asterisk/ /etc/lighttpd/lighttpd.conf /etc/odbc.ini /etc/odbcinst.ini /var/scripts/ ;
do
/bin/cp -r $i BACKUP/
done
# 3. CDR SQL dump on 28 day monthly
if [ $CDRDAY == 28 ]
then
$SQLDUMP -u root -pRoOtPaSsWoRd db_asterisk_cdr > BACKUP/db_asterisk_cdr.$DATE.sql
fi
# 4. archivate
$TAR $SRVNAME$DATE.tar.gz BACKUP/
# 5. delete shit
/bin/rm -rf BACKUP/
}
#------------------------------------------------
# fire!
if [ -d $BACKUP_DIR ]
then
bkuper
else
/bin/mkdir $BACKUP_DIR
bkuper
fi
# remove older than 30 days old backups
find $BACKUP_DIR -type f -name "*z" -mtime +30 -execdir rm -f {} \;
exit $?
Tags: backup, bash
This entry was posted on Tuesday, September 5th, 2017 at 11:15 and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed.
Both comments and pings are currently closed.