diff options
author | Brian Martin <bmartin@martinconsulting.com> | 2013-09-25 17:01:24 -0700 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2013-10-05 13:51:34 +0200 |
commit | 8fe1f405e915c1f37a810371a86ed39cfc7eddbe (patch) | |
tree | efb1c0e8f1afdd51fd63bab0902b5b294d3119e9 /source4/scripting/bin/samba_backup | |
parent | 6ccbc1347d3240fc3c874a1957b654456fb6234c (diff) | |
download | samba-8fe1f405e915c1f37a810371a86ed39cfc7eddbe.tar.gz samba-8fe1f405e915c1f37a810371a86ed39cfc7eddbe.tar.bz2 samba-8fe1f405e915c1f37a810371a86ed39cfc7eddbe.zip |
samba_backup: fix bug, add command line parameter, improve error messages
Also remove .bak suffix from tdb/ldb backups for more consistent restore procedures
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Matthieu Patou <mat@matws.net>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Sat Oct 5 13:51:34 CEST 2013 on sn-devel-104
Diffstat (limited to 'source4/scripting/bin/samba_backup')
-rwxr-xr-x | source4/scripting/bin/samba_backup | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/source4/scripting/bin/samba_backup b/source4/scripting/bin/samba_backup index 8f9cc838a7..3e22abecd9 100755 --- a/source4/scripting/bin/samba_backup +++ b/source4/scripting/bin/samba_backup @@ -15,24 +15,39 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # +# Revised 2013-09-25, Brian Martin, as follows: +# - Allow retention period ("DAYS") to be specified as a parameter. +# - Allow individual positional parameters to be left at the default +# by specifying "-" +# - Use IS0 8601 standard dates (yyyy-mm-dd instead of mmddyyyy). +# - Display tar exit codes when reporting errors. +# - Don't send error messages to /dev/null, so we know what failed. +# - Suppress useless tar "socket ignored" message. +# - Fix retention period bug when deleting old backups ($DAYS variable +# could be set, but was ignored). + + FROMWHERE=/usr/local/samba WHERE=/usr/local/backups +DAYS=90 # Set default retention period. if [ -n "$1" ] && [ "$1" = "-h" -o "$1" = "--usage" ]; then - echo "samba_backup [provisiondir] [destinationdir]" - echo "Will backup your provision located in provisiondir to archive stored in destinationdir" + echo "samba_backup [provisiondir] [destinationdir] [retpd]" + echo "Will backup your provision located in provisiondir to archive stored" + echo "in destinationdir for retpd days. Use - to leave an option unchanged." echo "Default provisiondir: $FROMWHERE" echo "Default destinationdir: $WHERE" + echo "Default destinationdir: $DAYS" exit 0 fi -[ -n "$1" -a -d "$1" ]&&FROMWHERE=$1 -[ -n "$2" -a -d "$2" ]&&WHERE=$2 +[ -n "$1" -a "$1" != "-" ]&&FROMWHERE=$1 # Use parm or default if "-". Validate later. +[ -n "$2" -a "$2" != "-" ]&&WHERE=$2 # Use parm or default if "-". Validate later. +[ -n "$3" -a "$3" -eq "$3" 2> /dev/null ]&&DAYS=$3 # Use parm or default if non-numeric (incl "-"). DIRS="private etc sysvol" #Number of days to keep the backup -DAYS=90 -WHEN=`date +%d%m%y` +WHEN=`date +%Y-%m-%d` # ISO 8601 standard date. if [ ! -d $WHERE ]; then echo "Missing backup directory $WHERE" @@ -52,24 +67,31 @@ for d in $DIRS;do find $relativedirname -name "*.ldb.bak" -exec rm {} \; for ldb in `find $relativedirname -name "*.ldb"`; do tdbbackup $ldb - if [ $? -ne 0 ]; then - echo "Error while backuping $ldb" + Status=$? # Preserve $? for message, since [ alters it. + if [ $Status -ne 0 ]; then + echo "Error while backing up $ldb - status $Status" exit 1 fi done - tar cjf ${WHERE}/samba4_${n}.${WHEN}.tar.bz2 $relativedirname --exclude=*.ldb >/dev/null 2>&1 - if [ $? -ne 0 ]; then - echo "Error while archiving ${WHERE}/samba4_${n}.${WHEN}.tar.bz2" + # Run the backup. + # --warning=no-file-ignored set to suppress "socket ignored" messages. + tar cjf ${WHERE}/samba4_${n}.${WHEN}.tar.bz2 $relativedirname --exclude=\*.ldb --warning=no-file-ignored --transform 's/.ldb.bak$/.ldb/' + Status=$? # Preserve $? for message, since [ alters it. + if [ $Status -ne 0 -a $Status -ne 1 ]; then # Ignore 1 - private dir is always changing. + echo "Error while archiving ${WHERE}/samba4_${n}.${WHEN}.tar.bz2 - status = $Status" exit 1 fi find $relativedirname -name "*.ldb.bak" -exec rm {} \; else - tar cjf ${WHERE}/${n}.${WHEN}.tar.bz2 $relativedirname >/dev/null 2>&1 - if [ $? -ne 0 ]; then - echo "Error while archiving ${WHERE}/${n}.${WHEN}.tar.bz2" + # Run the backup. + # --warning=no-file-ignored set to suppress "socket ignored" messages. + tar cjf ${WHERE}/${n}.${WHEN}.tar.bz2 $relativedirname --warning=no-file-ignored + Status=$? # Preserve $? for message, since [ alters it. + if [ $Status -ne 0 ]; then + echo "Error while archiving ${WHERE}/${n}.${WHEN}.tar.bz2 - status = $Status" exit 1 fi fi done -find $WHERE -name "samba4_*bz2" -mtime +90 -exec rm {} \; >/dev/null 2>&1 +find $WHERE -name "samba4_*bz2" -mtime +$DAYS -exec rm {} \; |