3 # Copyright (C) Matthieu Patou <mat@matws.net> 2010-2011
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 FROMWHERE
=/usr
/local
/samba
20 WHERE
=/usr
/local
/backups
21 if [ -n "$1" ] && [ "$1" = "-h" -o "$1" = "--usage" ]; then
22 echo "samba_backup [provisiondir] [destinationdir]"
23 echo "Will backup your provision located in provisiondir to archive stored in destinationdir"
24 echo "Default provisiondir: $FROMWHERE"
25 echo "Default destinationdir: $WHERE"
29 [ -n "$1" -a -d "$1" ]&&FROMWHERE
=$1
30 [ -n "$2" -a -d "$2" ]&&WHERE
=$2
32 DIRS
="private etc sysvol"
33 #Number of days to keep the backup
37 if [ ! -d $WHERE ]; then
38 echo "Missing backup directory $WHERE"
42 if [ ! -d $FROMWHERE ]; then
43 echo "Missing or wrong provision directory $FROMWHERE"
49 relativedirname
=`find . -type d -name "$d" -prune`
50 n
=`echo $d | sed 's/\//_/g'`
51 if [ "$d" = "private" ]; then
52 find $relativedirname -name "*.ldb.bak" -exec rm {} \
;
53 for ldb
in `find $relativedirname -name "*.ldb"`; do
56 echo "Error while backuping $ldb"
60 tar cjf
${WHERE}/samba4_${n}.${WHEN}.
tar.bz2
$relativedirname --exclude=*.ldb
>/dev
/null
2>&1
62 echo "Error while archiving ${WHERE}/samba4_${n}.${WHEN}.tar.bz2"
65 find $relativedirname -name "*.ldb.bak" -exec rm {} \
;
67 tar cjf
${WHERE}/${n}.${WHEN}.
tar.bz2
$relativedirname >/dev
/null
2>&1
69 echo "Error while archiving ${WHERE}/${n}.${WHEN}.tar.bz2"
75 find $WHERE -name "samba4_*bz2" -mtime +90 -exec rm {} \
; >/dev
/null
2>&1