vfstest: fix the "-c" multiple-command option
[Samba.git] / source4 / scripting / bin / samba_backup
blob8f9cc838a77ede9069a5788b72ae64ae5aed8d2f
1 #!/bin/sh
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"
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 if [ ! -d $WHERE ]; then
38 echo "Missing backup directory $WHERE"
39 exit 1
42 if [ ! -d $FROMWHERE ]; then
43 echo "Missing or wrong provision directory $FROMWHERE"
44 exit 1
47 cd $FROMWHERE
48 for d in $DIRS;do
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
54 tdbbackup $ldb
55 if [ $? -ne 0 ]; then
56 echo "Error while backuping $ldb"
57 exit 1
59 done
60 tar cjf ${WHERE}/samba4_${n}.${WHEN}.tar.bz2 $relativedirname --exclude=*.ldb >/dev/null 2>&1
61 if [ $? -ne 0 ]; then
62 echo "Error while archiving ${WHERE}/samba4_${n}.${WHEN}.tar.bz2"
63 exit 1
65 find $relativedirname -name "*.ldb.bak" -exec rm {} \;
66 else
67 tar cjf ${WHERE}/${n}.${WHEN}.tar.bz2 $relativedirname >/dev/null 2>&1
68 if [ $? -ne 0 ]; then
69 echo "Error while archiving ${WHERE}/${n}.${WHEN}.tar.bz2"
70 exit 1
73 done
75 find $WHERE -name "samba4_*bz2" -mtime +90 -exec rm {} \; >/dev/null 2>&1