#!/bin/sh # # $Id: 230.jailback,v 1.9 2011/03/28 22:33:23 andrew Exp $ # # This script replicates selected folders from jails to a remote # rsyncd server via SSH, in order to maintain a near-online # backup of data contained in our jails. # You need to put a file named .jailback in the root of each # jail, containing the list of the contents you need to sync. # Excluded patterns can be specified in an additional file # named .jailback-exclude, in the root of each jail. # # If there is a global system configuration file, suck it in. # if [ -r /etc/defaults/periodic.conf ] then . /etc/defaults/periodic.conf source_periodic_confs fi # If there is a readable ezjail configuration file, suck it in. # if [ -r /usr/local/etc/ezjail.conf ] then . /usr/local/etc/ezjail.conf fi # Defaults. # : ${daily_jailback_enable:=NO} : ${daily_jailback_dstdir:=`hostname -s`} : ${daily_jailback_srcdir:=/usr/jails} : ${daily_jailback_port:=22} # Backup via RSYNC over SSH all the directories written in the files .jailback, # which resides in the root of each jail. # case "$daily_jailback_enable" in [Yy][Ee][Ss]) echo echo "Backing up jails data:" if [ -z $daily_jailback_host ] ; then echo " STOP: no destination host was specified!" rc=2 exit $rc fi if [ $ezjail_jaildir ] ; then daily_jailback_srcdir=$ezjail_jaildir fi # Set the remote destination path rsync_dest=$daily_jailback_host:/var/backups/$daily_jailback_dstdir # Set environment variables parsed by rsync(1) export RSYNC_RSH="ssh -p $daily_jailback_port" # Start doing the job cd $daily_jailback_srcdir for jail in * ; do if [ -r $jail/.jailback ] ; then dirs=`sed -e '/^#/d' -e '/^$/d' -e "s/^/$jail\//" $jail/.jailback` if [ -n "$dirs" ] ; then if [ -r $jail/.jailback-exclude ] ; then exclude="--exclude-from=$jail/.jailback-exclude" fi echo $dirs | tr " " "\n" | \ /usr/local/bin/rsync -arz --delete --files-from="-" \ $exclude . $rsync_dest || rc=3 fi fi done ;; *) rc=0 ;; esac exit $rc