python:tests: Store keys as bytes rather than as lists of ints
[samba.git] / source4 / scripting / bin / samba_backup
1 #!/bin/sh
2 #
3 # Copyright (C) Matthieu Patou <mat@matws.net> 2010-2011
4 #
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.
9 #
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.
14 #
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/>.
17 #
18
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
27 fi
28
29 [ -n "$1" -a -d "$1" ]&&FROMWHERE=$1
30 [ -n "$2" -a -d "$2" ]&&WHERE=$2
31
32 DIRS="private etc sysvol"
33 #Number of days to keep the backup
34 DAYS=90
35 WHEN=`date +%d%m%y`
36
37 if [ ! -d $WHERE ]; then
38         echo "Missing backup directorty $WHERE"
39         exit 1
40 fi
41
42 if [ ! -d $FROMWHERE ]; then
43         echo "Missing or wrong provision directorty $FROMWHERE"
44         exit 1
45 fi
46
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
58                         fi
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
64                 fi
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
71                 fi
72         fi
73 done
74
75 find $WHERE -name "samba4_*bz2" -mtime +90 -exec rm  {} \; >/dev/null 2>&1