[Samba] samba4 backup script

NOC noc at nieuwland.nl
Mon Apr 22 06:47:18 MDT 2013


Hi list

I recently encountered errors while trying to backup the samba4 AD. 
Apparently tar had some problems with sockets in the samba4 directory.

I modified the samba4 backup script, perhaps this or a similar change is 
good to include upstream?

Cheers

Simon Oosthoek
-------------- next part --------------
#!/bin/sh
#####################################################
#       THIS FILE IS DISTRIBUTED BY PUPPET          #
#####################################################
#
# Copyright (C) Matthieu Patou <mat at matws.net> 2010-2011
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

FROMWHERE=/var/lib/samba4/
WHERE=/var/backup/samba4/
if [ -n "$1" ] && [ "$1" = "-h" -o "$1" = "--usage" ]; then
	echo "samba_backup [provisiondir] [destinationdir]"
	echo "Will backup your provision located in provisiondir to archive stored in destinationdir"
	echo "Default provisiondir: $FROMWHERE"
	echo "Default destinationdir: $WHERE"
	exit 0
fi

[ -n "$1" -a -d "$1" ]&&FROMWHERE=$1
[ -n "$2" -a -d "$2" ]&&WHERE=$2

DIRS="private sysvol"
#Number of days to keep the backup
DAYS=90
WHEN=$(date +%d%m%y)

if [ ! -d $WHERE ]; then
	echo "Missing backup directory $WHERE"
	exit 1
fi

if [ ! -d $FROMWHERE ]; then
	echo "Missing or wrong provision directory $FROMWHERE"
	exit 1
fi

cd $FROMWHERE
for d in $DIRS;do
	relativedirname=$(find . -type d -name "$d" -prune)
	n=$(echo $d | sed 's,/,_,g')
	if [ "$d" = "private" ]; then
		find $relativedirname -name "*.ldb.bak" -exec rm {} \;
		for ldb in $(find $relativedirname -name "*.ldb"); do
			if tdbbackup $ldb
			then :
			else
				echo "Error while backuping $ldb"
				exit 1
			fi
		done
		find "$relativedirname" -type f -o -type d |grep -v '\.ldb$' |cpio --quiet -o --format=tar |bzip2 >"$WHERE/samba4_${n}.$WHEN.tar.bz2" 
		if [ ! -f "$WHERE/samba4_${n}.$WHEN.tar.bz2" ] || [ $(stat -c "%s" "$WHERE/samba4_${n}.$WHEN.tar.bz2") -eq 0 ]; then
			echo "Error while archiving ${WHERE}/samba4_${n}.${WHEN}.tar.bz2"
			exit 1
		fi
		find $relativedirname -name "*.ldb.bak" -exec rm {} \;
	else
		find "$relativedirname" -type f -o -type d |cpio --quiet -o --format=tar |bzip2 >"$WHERE/${n}.$WHEN.tar.bz2" 
		if [ ! -f "$WHERE/${n}.$WHEN.tar.bz2" ] || [ $(stat -c "%s" "$WHERE/${n}.$WHEN.tar.bz2") -eq 0 ]; then
			echo "Error while archiving ${WHERE}/${n}.${WHEN}.tar.bz2"
			exit 1
		fi
	fi
done

find $WHERE -name "samba4_*bz2" -mtime +$DAYS -exec rm  {} \; >/dev/null 2>&1



More information about the samba mailing list