Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Firebird database backup script

  #!/bin/bash

#Below I change to 1 if I want to send the archive and not an email
#CHANGE AND PARAM FOR LOGIN
FTP_STATUS=0
FTP_USER=
FTP_PASSWORD=
FTP_URL=
#tuka ima nqkakava izmama shto ne moga da dobavq papkata kym patq
#zatova dobavqm i dolnoto
FTP_FOLDER=

#Hardcode param
#FB COMMON
USERNAME=SYSDBA
PASSWORD=masterkey
RUN=/opt/firebird/bin/gbak

#PATH PARAM
#PATH TO DATABASE
DATA_BASE=/home/username/database/FDB.FDB
FILE_NAME="${DATA_BASE##*/}"

#PATH TO BACKUP FOLDER
BACKUP_FOLDER=/home/username/backup

#ATTACH DATA AND TIME TO ARHIVE
DATA_TIME=`date +%d-%m-%Y-%H-%M`

#CONCAT FILE WITH DATA TIME
CREATE_BACKUP=${FILE_NAME%%.*}-$DATA_TIME.FBK

#USER FRANDLY TAR ARHIVE
ZIP_FILE_BACKUP=${CREATE_BACKUP%%.*}.tar.gz
#HOW MUCH ARCHIVE SAVE
SAVE=3

#CHECK IF FOLDER EXISTS AND CHANGE OWNER

if [ ! -d $BACKUP_FOLDER ];then
mkdir -p $BACKUP_FOLDER && chown -R firebird.firebird $BACKUP_FOLDER
else
chown -R firebird.firebird $BACKUP_FOLDER
fi

#MAKE BACKUP AND THEN CREATE ZIP FILE FROM ARHIVE THEN ARHIVE DELETED
$RUN -g -t -user $USERNAME -password $PASSWORD $DATA_BASE $BACKUP_FOLDER/$CREATE_BACKUP
`tar -czf $BACKUP_FOLDER/$ZIP_FILE_BACKUP $BACKUP_FOLDER/$CREATE_BACKUP`
`ls -d -1tr $BACKUP_FOLDER/* | grep FBK$ | head -n1 | xargs rm -rf`

#CHECK HOW MUCH ARCHIVE HAVE AND DELETE IF BIGGER THEN SAVE OARAM

if [ $(ls -d -1tr $BACKUP_FOLDER/* | grep tar.gz$ | wc -l) -gt $SAVE ];then
`ls -d -1tr $BACKUP_FOLDER/* | grep tar.gz$ | head -n1 | xargs rm -rf`
fi

if [ $FTP_STATUS -eq 1 ];then
cd $BACKUP_FOLDER &&
FTP_FILE=`ls -1t | head -n1`

ftp -inv $FTP_URL user $FTP_USER $FTP_PASSWORD
cd $FTP_FOLDER
put $FTP_FILE
bye
EOF
fi



This post first appeared on Linux Command's, please read the originial post: here

Share the post

Firebird database backup script

×

Subscribe to Linux Command's

Get updates delivered right to your inbox!

Thank you for your subscription

×