s3:idmap_tdb2: fix bug 8368 : correctly initialize "idmap config * : script" with...
[Samba.git] / source4 / scripting / bin / samba_backup
blob56125789d86e9c05343e16784578eda5c2fb8f92
1 #!/bin/sh
3 # Copyright (C) Matthieu Patou <mat@matws.net> 2010
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"
26 exit 0
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
34 DAYS=90
35 WHEN=`date +%d%m%y`
37 cd $FROMWHERE
38 for d in $DIRS;do
39 relativedirname=`find . -type d -name "$d" -prune`
40 n=`echo $d | sed 's/\//_/g'`
41 if [ "$d" = "private" ]; then
42 find $relativedirname -name "*.ldb.bak" -exec rm {} \;
43 for ldb in `find $relativedirname -name "*.ldb"`; do
44 tdbbackup $ldb
45 if [ $? -ne 0 ]; then
46 echo "Error while backuping $ldb"
47 exit 1
49 done
50 tar cjf ${WHERE}/samba4_${n}.${WHEN}.tar.bz2 $relativedirname --exclude=*.ldb >/dev/null 2>&1
51 if [ $? -ne 0 ]; then
52 echo "Error while archiving ${WHERE}/samba4_${n}.${WHEN}.tar.bz2"
53 exit 1
55 find $relativedirname -name "*.ldb.bak" -exec rm {} \;
56 else
57 tar cjf ${WHERE}/${n}.${WHEN}.tar.bz2 $relativedirname >/dev/null 2>&1
58 if [ $? -ne 0 ]; then
59 echo "Error while archiving ${WHERE}/${n}.${WHEN}.tar.bz2"
60 exit 1
63 done
65 find $WHERE -name "samba4_*bz2" -mtime +90 -exec rm {} \; >/dev/null 2>&1