Skip to content

Instantly share code, notes, and snippets.

@piavlo
Created January 15, 2013 17:55
Show Gist options
  • Save piavlo/4540491 to your computer and use it in GitHub Desktop.
Save piavlo/4540491 to your computer and use it in GitHub Desktop.
rsync per defined local filesystem in /etc/fstab finds all mountpoint that start with /backup like /backup/path and backups /path to /backup/path
#!/bin/bash
exec > /var/log/`basename ${0}`.log 2>&1
echo "############ `date` ###########"
for bkdir in `cat /etc/fstab | egrep -v -e '^#' | egrep -e '[[:space:]]/backup' | awk '{print $2}'` ; do
mount | egrep -e '[[:space:]]'${bkdir}'[[:space:]]' > /dev/null
if [ $? == 0 ]; then
dir=`echo ${bkdir} | sed -e 's#/backup##' `
[ "X${dir}" == "X" ] && dir="/"
mount | egrep -e '[[:space:]]'${dir}'[[:space:]]' > /dev/null
if [ $? == 0 ]; then
touch ${dir}/cs-fs-check 2>&1 | egrep -e 'Read-only file system' > /dev/null
if [ $? == 0 ]; then
echo "### ${dir} is Read Only not rsyncing ###"
continue
fi
rm -f ${dir}/cs-fs-check
params="-aWHvx"
mount | egrep -e '[[:space:]]'${bkdir}'[[:space:]]' | egrep -e '\((|.*,).*acl(|,.*)\)' > /dev/null
if [ $? == 0 ]; then
params="$params -A"
fi
if [ "${dir}" == "/" ]; then
dir=$(mktemp -d /tmp/`basename ${0}`.root.XXXXXX)
mount -o bind / $dir
echo "### Rsync of / ###"
rsync $params --exclude="/etc/fstab" --delete ${dir}"/" ${bkdir}"/"
umount $dir
rmdir $dir
cs-fstab-bkup
else
echo "### Rsync of ${dir} ###"
rsync $params --exclude="/etc/fstab" --delete ${dir}"/" ${bkdir}"/"
fi
fi
fi
done
echo "############ `date` ###########"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment