source: trunk/confsync.in @ 585

Revision 585, 4.6 KB checked in by blee, 5 months ago (diff)

Introduce new option CONF_EXPORT_FILEDB.

This allows confexport to convert repository metadata into a
proprietary file-backed metadata format and exclude all Subversion
working-copy-related files from exports.

confsync has been modified to automatically detect the presence of
the new metadata format and use it if it is available.

This has multiple benefits:

  • Significantly reduces the size of export tarballs
  • Reduces the time to generate export tarballs
  • Eliminates the requirement that confexport/confsync have matching versions of Subversion
  • Significantly improves confsync performance by eliminating svn forks

There will be even further benefits when ticket #151 is closed because
the repository metadata wil not need to be converted during confexport.

Fixes #139

  • Property svn:executable set to *
  • Property svn:keywords set to Id
Line 
1#!@BASH@
2#
3# Copyright (c) 2008, Christopher Cowart and contributors
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# * Redistributions of source code must retain the above copyright
10#   notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above copyright
12#   notice, this list of conditions and the following disclaimer in the
13#   documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# $Id$
28#
29# This script obtains the latest "export" from confman and installs
30# it onto the system. It is intended to be used in crons as the
31# configuration pulling mechanism.
32
33if [ -r @pkgdatadir@/confmancommon.sh ] ; then
34    . @pkgdatadir@/confmancommon.sh
35else
36    echo "Can't find confmancommon.sh. Exiting." >&2
37    exit 17
38fi
39
40function print_help {
41    echo "usage: $0 [-f] [-s] [-d]" >&4
42    echo "Type '$0 -h' to display this help and exit." >&4
43    conf_cleanExit ${1:-0}
44}
45
46FORCE=false
47QUIET=false
48sleep_mode=false
49
50while getopts "fqsdh" OPT 2>&4 ; do
51    case $OPT in
52        f)  FORCE=true ;;
53        s)  sleep_mode=true ;;
54        d)  DEBUG=true ;;
55        q)  QUIET=true ;;
56        h)  print_help 0;;
57        *)  print_help 1;;
58    esac
59done
60
61# If we're in debug mode, we should log stderr messages to the logger
62# as well. Otherwise, we send them to the bit bucket.
63if $DEBUG ; then
64    exec 1>&2
65else
66    exec 1>/dev/null
67fi
68
69system_lock=$(conf_lock_system)
70
71conf_require_recipe
72
73if $sleep_mode; then
74    if [ -n "${CONF_SYNC_SLEEP}" ] && [ ${CONF_SYNC_SLEEP} -ge 0 ]; then
75        echo "Sleeping ${CONF_SYNC_SLEEP} seconds..."
76        sleep ${CONF_SYNC_SLEEP}
77    else
78        echo "Invalid sleep value: ${CONF_SYNC_SLEEP}" >&2
79        exit 1
80    fi
81fi
82
83# Set up our "Working Copy"
84tmpdir=$(conf_tmp_dir)
85WORK_PATH="$tmpdir"
86
87tarpath=$(conf_fetch)
88if ! [ -s $tarpath ] ; then
89    echo "Could not fetch the export." >&2
90    exit 1
91fi
92
93case ${CONF_EXPORT_STYLE} in
94    repository|recipe)
95        tar -xzf $tarpath -C $tmpdir
96        ;;
97    module)
98        for layer in $(conf_get_recipe); do
99            tarfile="$tarpath/$layer.tgz"
100            if ! [ -s $tarfile ]; then
101                echo "Could not fetch the export." >&2
102                exit 1
103            fi
104            tar -xzf $tarfile -C $tmpdir
105        done
106        ;;
107    *)
108        echo "Unsupported export style." >&2
109        exit 1
110        ;;
111esac
112
113rm -rf $tarpath
114
115tar_revision=`conf_revision`
116sys_revision=`conf_sysrev`
117last_action=$(conf_lastact)
118statefile=$(conf_tmp_file)
119
120if [ -n "${sys_revision}" ] ; then
121    if [ "${tar_revision}" -lt "${sys_revision}" ]; then
122        echo "Error: ${tarpath} is out of date. Exiting without making changes." >&2
123        conf_markdirty
124        conf_cleanExit 1
125    elif ! ${FORCE} && [ "${tar_revision}" -eq "${sys_revision}" ]; then
126        if [ "${last_action}" = "commit" -o "${last_action}" = "sync" ]; then
127            ${QUIET} || echo "System is up to date." | conf_logger
128            conf_cleanExit 0
129        fi
130    fi
131fi
132
133echo "Sync operation started" | conf_logger
134for layer in $(conf_get_reverse_recipe) ; do
135    echo "Rolling on $layer..."
136
137    # XXX: Until ticket #151 is resolved, prefer to use the fdb metadata
138    # when it is available
139    if [ -r "$(conf_meta_dir)/${layer}.fdb" ]; then
140        declare -A metadata
141        filedb_load "$(conf_meta_dir)/${layer}.fdb" "metadata"
142        CONF_GET_PROP_USE_FDB="true"
143    fi
144
145    conf_rollout $layer $statefile || conf_cleanExit
146
147    if ${CONF_GET_PROP_USE_FDB}; then
148        unset metadata
149    fi
150done
151for file in $SINGULARITIES ; do
152    conf_assemble_sing $file || conf_cleanExit
153done
154conf_markclean
155conf_recordAction sync
156echo "Sync operation finished successfully" | conf_logger
157
158conf_unlock_system $system_lock
159
160rm -rf $tmpdir
161
162conf_cleanExit 0
163
Note: See TracBrowser for help on using the repository browser.