Backup using Backup Server

Copy the file budata.sh from WEB-INF into the /root folder in the backup server. Follow the instructions in the header.

#!/bin/sh
#========================
#Place this file in the /root folder of the backup server
# 
#
#on backup server
#(1) Generate key on backup server
#ssh-keygen -t rsa
#
#(2) Copy the key into the autorized_keys of the source server
#
#ssh root@source.dreamapps.com  mkdir -p .ssh
#cat .ssh/id_rsa.pub | ssh root@source.dreamapps.com 'cat >> .ssh/authorized_keys'
#
#(3) On backup server
#
# /root/budata.sh source
#
#(4) Automate it
#
# crontab -e
#
# daily : 1 1 * * * /path/to/script/budata.sh
# weekly: 1 1 * * 0 /path/to/script/budata.sh 
#
# 30 03 * * * /root/budata.sh sg01
#
# will backup the data in sg01.dreamapps.com daily at 3:30 am
#
#========================
# here=`pwd`
pathname=$(readlink -f "$0")
arg=$1''
####  YOU MAY NEED TO CHANGE ONLY THE NEXT 3 LINES  ####

myhost=${arg}'.dreamapps.com'
budir='data'
relpathtowiki='/var/lib/pgsql/data/'

####  YOU MAY NEED TO CHANGE ONLY THE LAST 3 LINES  ####

mydate="`date '+%Y%m%d.%H%M'`"
 
# Define wiki location
#myhost='${svr}'                     #name of the server hosting your your wiki
myuser='root'                          #name of the user that has an ssh access to "myhost"
#relpathtowiki='/var/lib/pgsql/data/'  #relative path to your wiki from "myhost" base
backupsource="${myuser}@${myhost}:${relpathtowiki}"
#backupsource="/abs/path/to/wiki/" #Use this line instead of the above if you run the backup script directly on your www server.
 
# Define location of backup
#backupdir="/home/ds1184/bu/${myhost}/data"
backupdir="/home/ds1184/bu/${myhost}/${budir}"
logfile="${backupdir}/backup.log"
excludelist="${pathname}-exclude.txt"
bkname="backup"
 
nbbackup="7" # keep this amount of old backup
 
#-- creates $1, if not existant
checkDir() {
    if [ ! -d "${backupdir}/$1" ] ; then
        mkdir -p "${backupdir}/$1"
    fi
}
 
# 1 -> path
# 2 -> name
# 3 -> number of backups
rotateDir() {
    for i in `seq $(($3 - 1)) -1 0`
      do
      if [ -d "$1/$2-$i" ] ; then
          /bin/rm -f "$1/$2-$((i + 1))"
          mv "$1/$2-$i" "$1/$2-$((i + 1))"
      fi
    done
}
 
#-- make sure everything exists
checkDir "archive"
checkDir "daily"
 
#-- first step: rotate daily.
rotateDir "${backupdir}/daily" "$bkname" "$nbbackup"
 
mv ${logfile} ${backupdir}/daily/${bkname}-1/
 
cat >> ${logfile} <<_EOF
===========================================
  Backup done on: $mydate
===========================================
_EOF
 
#-- Do the backup and save difference in backup-1
mkdir -p ${backupdir}/daily/${bkname}-1/
mkdir -p ${backupdir}/daily/${bkname}-0/
cd ${backupdir}/daily/${bkname}-0
rsync -av --whole-file --delete --force \
    -b --backup-dir ${backupdir}/daily/${bkname}-1/${thisdir} \
    --exclude-from=${excludelist} \
    $backupsource . \
    1>> ${logfile} 2>&1
 
#-- create an archive backup every month
lastarchivetime="0"
if [ -r ${backupdir}/lastarchivetime ] ; then
  lastarchivetime=`cat ${backupdir}/lastarchivetime`
fi
now=`date +%j`
let diffday=$now-$lastarchivetime
if [ $diffday  -ge 30 -o $diffday -lt 0 ] ; then
    echo $now > ${backupdir}/lastarchivetime
    cd ${backupdir}/daily
    tar -cjf ${backupdir}/archive/${bkname}-${mydate}.tar.bz2 ./${bkname}-0
fi