From d1feb03889935425b83e2bd5007bd90fddc62927 Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Fri, 22 Oct 2010 13:28:40 +0400 Subject: Add a script to make backup of samba provision --- source4/scripting/bin/samba_backup | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 source4/scripting/bin/samba_backup (limited to 'source4/scripting/bin/samba_backup') diff --git a/source4/scripting/bin/samba_backup b/source4/scripting/bin/samba_backup new file mode 100755 index 0000000000..fabf60cf2c --- /dev/null +++ b/source4/scripting/bin/samba_backup @@ -0,0 +1,65 @@ +#!/bin/sh +# +# Copyright (C) Matthieu Patou 2010 +# +# 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 . +# + +FROMWHERE=/usr/local/samba +WHERE=/usr/local/backups +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 etc sysvol" +#Number of days to keep the backup +DAYS=90 +WHEN=`date +%d%m%y` + +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 $refativedirname -name "*.ldb.bak" -exec rm {} \; + for ldb in `find $refativedirname -name "*.ldb"`; do + tdbbackup $ldb + if [ $? -ne 0 ]; then + echo "Error while backuping $ldb" + exit 1 + fi + done + tar cjf ${WHERE}/samba4_${n}.${WHEN}.tar.bz2 $relativedirname --exclude=*.ldb >/dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error while archiving ${WHERE}/samba4_${n}.${WHEN}.tar.bz2" + exit 1 + fi + find $refativedirname -name "*.ldb.bak" -exec rm {} \; + else + tar cjf ${WHERE}/${n}.${WHEN}.tar.bz2 $relativedirname >/dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error while archiving ${WHERE}/${n}.${WHEN}.tar.bz2" + exit 1 + fi + fi +done + +find $WHERE -name "samba4_*bz2" -mtime +90 -exec rm {} \; >/dev/null 2>&1 -- cgit