ccollect/tools/old/ccollect_create_source.sh

76 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2007-08-07 05:48:52 +00:00
#!/bin/sh
# Nico Schottelius
# 2007-08-07
# Written for Netstream (www.netstream.ch)
# Creates a source, including exclude
2007-08-07 06:21:40 +00:00
# standard values
2007-08-07 05:48:52 +00:00
CCOLLECT_CONF=${CCOLLECT_CONF:-/etc/ccollect}
CSOURCES=$CCOLLECT_CONF/sources
CDEFAULTS=$CCOLLECT_CONF/defaults
2007-08-07 06:40:44 +00:00
self=$(basename $0)
2007-08-07 06:21:40 +00:00
# functions first
_echo()
{
2007-08-07 08:27:17 +00:00
echo "${self}> $@"
2007-08-07 06:21:40 +00:00
}
_exit_err()
{
_echo "$@"
rm -f "$TMP"
exit 1
}
# argv
if [ $# -ne 3 ]; then
_echo "<name of the ccollect-source> <servername> <destination>"
_echo "Example: \"my-notebook\" \"192.168.42.42\" \"/home/server/backup/my-notebook\""
2007-08-07 06:21:40 +00:00
exit 1
fi
2007-08-07 05:48:52 +00:00
name="$1"
source="$2"
destination="$3"
2007-08-07 05:48:52 +00:00
fullname="${CSOURCES}/${name}"
2007-08-07 06:21:40 +00:00
# Tests
2007-08-07 05:48:52 +00:00
if [ -e "${fullname}" ]; then
2007-08-07 06:21:40 +00:00
_echo "${fullname} already exists. Aborting."
2007-08-07 05:48:52 +00:00
exit 2
fi
2007-08-07 06:21:40 +00:00
_echo "Trying to reach ${source} ..."
ping -c1 "${source}" || _exit_err "Cannot reach ${source}. Aborting."
2007-08-07 06:21:40 +00:00
# Create
_echo "Creating ${fullname} ..."
mkdir -p "${fullname}" || exit 3
echo "root@${source}:/" > "${fullname}/source"
2007-08-07 06:40:44 +00:00
cat << eof > "${fullname}/exclude" || exit 4
2007-08-07 06:21:40 +00:00
/dev/*
/proc/*
/tmp/*
eof
2007-08-07 06:40:44 +00:00
# Destination
if [ -e "${destination}" ]; then
if [ ! -d "${destination}" ]; then
echo "${destination} exists, but is not a directory. Aborting."
exit 5
fi
else
2007-08-07 08:28:59 +00:00
_echo "Creating ${destination} ..."
2007-08-07 06:40:44 +00:00
mkdir -p "${destination}" || _exit_err "Failed to create ${destination}."
fi
ln -s "${destination}" "${fullname}/destination" || \
_exit_err "Failed to link \"${destination}\" to \"${fullname}/destination\""
2007-08-07 06:21:40 +00:00
# finish
_echo "Added some default values, please verify \"${fullname}\"."
2007-08-07 06:21:40 +00:00
_echo "Finished."