← Back to team overview

nssbackup-team team mailing list archive

Re: [Question #112940]: command line control on full - incremental backup

 

Question #112940 on NSsbackup changed:
https://answers.launchpad.net/nssbackup/+question/112940

paolocollector posted a new comment:
here is the script:
basically it uses mysqldump or mysqladmin to backup mysql (full or incremental)
and two scripts to backup svn (will post them too if interested)
The script runs every day (if system is running) and performs a full backup after "maxIncDays" days

#!/bin/bash
#
# backup script used by anacron

maxIncDays=7
lastFullDateFile="/var/backup.extra/lastFullDateFile"
today=`date +%Y%m%d`
fullBackup=true

function dayDiff (){
	dateOfPast=$1
	timeStampToday=`date +%s -d $today`
	timeStampOfPast=`date +%s -d $dateOfPast`
	secondsInDay=86400
	dayDiff=`echo \($timeStampToday - $timeStampOfPast\) / $secondsInDay | bc`
	echo $dayDiff
}

#redirect stdout and stderr
logFile=/var/backup.extra/log/backup.`date +%Y-%m-%d`.log
errFile=/var/backup.extra/log/backup.`date +%Y-%m-%d`.err
exec &> $logFile
#exec 2> $errFile

echo "starting backup"|/usr/bin/wall

# if lastFullDateFile does not exist, set it to long time ago (backup will be done)
if [ ! -f $lastFullDateFile ]
then
	echo "20000101">$lastFullDateFile
fi

# get the last backup date and comare it to today
lastBackupDay=`cat $lastFullDateFile`
result=$(dayDiff $lastBackupDay )

# check result for a full or incremental backup
if [ "$result" -ge "$maxIncDays" ]
then
    full=true
	echo "$today">$lastFullDateFile
else
    full=false
fi

# extract mySql tables
if [ "$full" == true ]
then
	echo "full mySql backup begin..."
	mysqldump -proot --single-transaction --flush-logs --master-data=2 --all-databases --delete-master-logs > /var/backup.extra/mysql/fullBackup.sql
	echo "full mySql backup end"
else
	echo "incremental mySql backup begin..."
	mysqladmin -proot flush-logs
	echo "incremental mySql backup end"
fi

# extract subversion repository
if [ "$full" == true ]
then
	echo "full subversion backup begin..."
	/opt/scripts/svnFullBackup.pl
	echo "full subversion backup end"
else
	echo "incremental subversion backup begin..."
	/opt/scripts/svnIncBackup.pl
	echo "incremental subversion backup end"
fi

if [ -x /usr/bin/nssbackupd ]
then

	if [ "$full" == true ]
	then
		echo "full nssbackup backup begin..."
		/usr/bin/nssbackupd
		echo "full nssbackup backup end"
	else
		echo "incremental nssbackup backup begin..."
		/usr/bin/nssbackupd
		echo "incremental nssbackup backup end"
	fi

else
	echo error: /usr/sbin/sbackupd file not found
fi

echo "backup completed"|/usr/bin/wall

-- 
You received this question notification because you are a member of
NSsbackup team, which is an answer contact for NSsbackup.