| 1 | #!/bin/sh
|
|---|
| 2 | #
|
|---|
| 3 | # Copyright (C) Matthieu Patou <mat@matws.net> 2010
|
|---|
| 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 | 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
|
|---|
| 48 | fi
|
|---|
| 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
|
|---|
| 54 | fi
|
|---|
| 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
|
|---|
| 61 | fi
|
|---|
| 62 | fi
|
|---|
| 63 | done
|
|---|
| 64 |
|
|---|
| 65 | find $WHERE -name "samba4_*bz2" -mtime +90 -exec rm {} \; >/dev/null 2>&1
|
|---|