Syncvar
Jump to navigation
Jump to search
syncvar
#!/bin/sh
#
# Copyright (c) 2007 Matt Simerson
# All rights reserved.
#
# NOTE: this script runs early in the startup process, before
# /usr is available. It requires that a statically compiled
# version of rsync is installed in /bin/rsync.
#
# PROVIDE: syncvar
# REQUIRE: mountcritlocal var
# KEYWORD: shutdown # added per tom mazzotta
. /etc/rc.subr
name="syncvar"
rcvar=`set_rcvar`
command="/bin/rsync"
excludes="--exclude spool/ --exclude tmp/ --exclude empty/"
syncvar_enable=${syncvar_enable-"NO"}
syncvar_dir=${syncvar_dir-"/var.disk"}
start_cmd="syncvar_start"
stop_cmd="syncvar_stop"
load_rc_config $name
required_dirs="${syncvar_dir}"
syncvar_start () {
echo "Syncing var from disk."
# $command -a $excludes $syncvar_dir/ /var/ # nice and quiet
$command -av $excludes $syncvar_dir/ /var/ # noisy!
}
syncvar_stop () {
echo "Syncing var to disk."
more_excludes="--exclude run/ --exclude entropy/ --exclude supervise/"
# remount our $syncvar_dir as r/w
( /sbin/mount -u -o rw $syncvar_dir || # HD boot
/sbin/mount -u -o rw / || # CF boot
( echo "Failed to sync var to disk!" && exit 1 )
)
# just show us what it would do
# $command -avn $excludes $more_excludes /var/ $syncvar_dir/
# do the deed
$command -av $excludes $more_excludes /var/ $syncvar_dir/
# do it quietly
# $command -a $excludes $more_excludes /var/ $syncvar_dir/
}
run_rc_command "$1"