#!/bin/sh umask 026 PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin LOGDIR="/var/log/xfsdump" DUMPDIR="/var/backup" # An NFS mount would be a good idea COMPRESS=gzip # unset for none COMPSUFF="gz" # Suffix for compression program LEVEL="9" # default to incremental at level 9 while [ $# -ge 1 ]; do case $1 in -l ) LEVEL=$2 shift ;; -v ) VERBOSE=1 ;; * ) echo "Usage: $0 [-l level]" exit 0 ;; esac shift done hostname=`hostname` me=`which $0` mybase=`basename $0` mypath=`dirname $me` [ -x $mypath/$mybase.local ] && $mypath/$mybase.local croak() { test $VERBOSE && echo $1 } dumppart() { partition=$1 description=$2 level=$3 croak "Dumping $partition ($description) with level $level" # Set up logging logfile="${LOGDIR}/${description}.log" croak "logging to $logfile" mkdir -p `dirname $logfile` && touch $logfile if [ $level != 0 ]; then hasfull=`xfsrestore -I level=0,mnt="$hostname:$partition" | sed 's/\s//g' | awk -F: '($1 == "pathname") {print $2}'` if [ -z "$hasfull" ]; then echo "$mybase: Level 0 inventory for $partition not found" | tee -a $logfile echo "$mybase: Switching to level 0 (full backup)" | tee -a $logfile level=0 fi fi # Calculate file name to use dumpfile="${DUMPDIR}/$hostname/${description}_level${level}.xfsdump" croak "Dumping $partition to $dumpfile" mkdir -p `dirname $dumpfile` # Mount if necessary mounted=`mount $partition 2>&1 | grep already` partname=`df $partition | tail -n 1 | awk '{print $1}'` longdesc="$description-level-$level" # Clean up inventory xfsinvutil >/dev/null 2>&1 -n -M ${hostname}:$partition -m "$longdesc" 01/01/2020 # Remove old backup files if [ -f "$dumpfile" ]; then croak "Removing old dump file $dumpfile" rm -f "$dumpfile" fi if [ $VERBOSE ]; then verbosity="-p30 -v verbose" else verbosity="-v silent" fi # Just in case sync ### # The actual dump happens here # xfsdump 2>>$logfile $verbosity -E -F -e -L "$partname" -M "$longdesc" -l $level -f $dumpfile $partition # ### [ -z "$mounted" ] && umount $partition if [ ! -z $COMPRESS ] && [ -f "$dumpfile" ]; then if [ ! -z $COMPSUFF ] && [ -f "$dumpfile.$COMPSUFF" ]; then croak "Removing old compressed dump file $dumpfile.$COMPSUFF" rm -f "$dumpfile.$COMPSUFF" fi # Calculate compression level, values -0 to -9 valid complevel=-$(expr $level + 1) if [ $complevel -lt -9 ]; then complevel="-9" fi if [ $complevel -gt 0 ]; then complevel="0" fi croak "Compressing $dumpfile with $COMPRESS $complevel" $COMPRESS $complevel "$dumpfile" fi # All done for this partition croak "Dump $longdesc completed" } # Run xfsdump inventory consistency check xfsinvutil -FC >/dev/null vols=`grep -v '^#' /etc/fstab | grep -v '^$' |\ awk '($3 == "xfs" && $5 != 0) {print "dumppart",$2,$1,"$LEVEL;"}' |\ sed 's/LABEL=//'` eval $vols exit 0