Compare commits

...

24 Commits
2.7 ... master

Author SHA1 Message Date
Darko Poljak b50b3f64dc Update gitignore 2020-11-25 16:21:44 +01:00
Darko Poljak 40dbfbd3a3 Fix test: also count 'current' symlink 2020-11-25 16:20:28 +01:00
Darko Poljak 7d298d2b51 ++changelog 2020-11-25 16:17:29 +01:00
poljakowski 3687267dd7 Merge branch 'fix-current-symlink' into 'master'
Improve 'current' symlink to backup destinations

See merge request ungleich-public/ccollect!16
2020-11-25 16:15:27 +01:00
Jun Futagawa 2ca7598593 Improve 'current' symlink to backup destinations 2020-11-25 11:24:37 +09:00
Darko Poljak 08cb857664 Release 2.10 2020-08-26 08:36:43 +02:00
Darko Poljak 309d8dc773 ++changelog 2020-05-25 17:52:23 +02:00
poljakowski fabdefad82 Merge branch 'master' into 'master'
Add 'current' symlink to backup destinations

See merge request ungleich-public/ccollect!15
2020-05-25 17:51:13 +02:00
Steffen Zieger 616b1d9e3e Add 'current' symlink to backup destinations 2020-05-25 16:16:32 +02:00
Darko Poljak 7a7dec7751 Release 2.9 2020-05-25 12:05:35 +02:00
Darko Poljak 28dec3694a ++changelog 2020-05-24 17:29:29 +02:00
poljakowski 59b50e7f4b Merge branch 'ungleich-master-patch-28394' into 'master'
make rsync return code available in post_exec

See merge request ungleich-public/ccollect!14
2020-05-24 17:28:31 +02:00
Steffen Zieger a261ef841e make rsync return code available in post_exec 2020-05-24 16:40:04 +02:00
Darko Poljak 109b70ea76 gitlab runner should have necessary tools 2019-12-02 09:29:02 +01:00
Darko Poljak 5341de86fb Release 2.8 2019-11-26 06:10:17 +01:00
Darko Poljak 987277f1cf Update Makefile
Simplify and generalize.
2019-11-25 20:52:48 +01:00
Darko Poljak 589fed6107 ++changelog 2019-11-25 14:41:41 +01:00
Darko Poljak 61ab45fc65 Fix excluding destination dir from removal
Touch can lead to wrong ls order, and destination dir gets selected for
removal.
Use grep -v to exclude, instead of touch.
2019-11-25 14:38:17 +01:00
Darko Poljak 6c24e8a7d3 Fix quoting in tests 2019-11-25 13:44:10 +01:00
Darko Poljak 42bd1afb09 Fix quoting in tests 2019-11-25 13:35:22 +01:00
Darko Poljak 9ed5912461 Improve unit tests 2019-11-25 08:42:42 +01:00
Darko Poljak 5ce3fddf62 Define gitlab CI 2019-11-24 23:01:34 +01:00
Darko Poljak 8f5d9b2c97 Add unit testing 2019-11-15 08:29:46 +01:00
Darko Poljak 401dd4fa8e Fix path with spaces in eval 2019-11-15 08:29:46 +01:00
59 changed files with 139 additions and 135 deletions

2
.gitignore vendored
View File

@ -8,10 +8,10 @@ doc/man/*.html
doc/man/*.htm
doc/man/*.texi
doc/man/*.man
test/*
.*.swp
doc/man/*.[0-9]
doc/*.xml
doc/*/*.xml
*.texi
*.fo
*.lock

12
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,12 @@
stages:
- test
unit_tests:
stage: test
script:
- make test
shellcheck:
stage: test
script:
- make shellcheck

View File

@ -29,7 +29,7 @@ ASCIIDOC=asciidoc
DOCBOOKTOTEXI=docbook2x-texi
DOCBOOKTOMAN=docbook2x-man
XSLTPROC=xsltproc
XSL=/usr/share/xml/docbook/stylesheet/nwalsh/html/docbook.xsl
XSL=/usr/local/share/xsl/docbook/html/docbook.xsl
A2X=a2x
prefix=/usr/packages/ccollect-git
@ -41,11 +41,7 @@ manlink=/usr/local/man/man1
path_dir=/usr/local/bin
path_destination=${path_dir}/${CCOLLECT_DEST}
# where to publish
host=localhost
dir=/home/users/nico/privat/rechner/netz/seiten/www.nico.schottelius.org/src/software/ccollect
docdir=${dir}/documentation
docs_archive_name=docs.tar
#
# Asciidoc will be used to generate other formats later
@ -79,6 +75,8 @@ DOCBDOCS = ${DOCS:.text=.docbook}
DOC_ALL = ${HTMLDOCS} ${DBHTMLDOCS} ${TEXIDOCS} ${MANPDOCS} ${PDFDOCS}
TEST_LOG_FILE = /tmp/ccollect/ccollect.log
#
# End user targets
#
@ -89,6 +87,8 @@ all:
@echo "info: only generate Texinfo"
@echo "man: only generate manpage{s}"
@echo "install: install ccollect to ${prefix}"
@echo "shellcheck: shellcheck ccollect script"
@echo "test: run unit tests"
html: ${HTMLDOCS}
htm: ${DBHTMLDOCS}
@ -177,9 +177,9 @@ pub:
git push
publish-doc: documentation
@echo "Transferring files to ${host}"
@chmod a+r ${DOCS} ${DOC_ALL}
@tar c ${DOCS} ${DOC_ALL} | ssh ${host} "cd ${dir}; tar xv"
@tar cf ${docs_archive_name} ${DOCS} ${DOC_ALL}
@echo "Documentation files are in ${docs_archive_name}"
#
# Distribution
@ -202,9 +202,49 @@ dist: distclean documentation
shellcheck: ./ccollect
shellcheck -s sh -f gcc -x ./ccollect
test: $(CCOLLECT_SOURCE) /tmp/ccollect
test-nico: $(CCOLLECT_SOURCE) /tmp/ccollect
cd ./conf/sources/; for s in *; do CCOLLECT_CONF=../ ../../ccollect daily "$$s"; done
touch /tmp/ccollect/$$(ls /tmp/ccollect | head -n1).ccollect-marker
CCOLLECT_CONF=./conf ./ccollect -a daily
touch /tmp/ccollect/$$(ls /tmp/ccollect | head -n1).ccollect-marker
CCOLLECT_CONF=./conf ./ccollect -a -p daily
test-dir-source:
mkdir -p /tmp/ccollect/source
cp -R -f ./* /tmp/ccollect/source
test-dir-destination:
mkdir -p /tmp/ccollect/backup
test-dir-destination-chint:
mkdir -p /tmp/ccollect/backup-chint
test-fixed-intervals: $(CCOLLECT_SOURCE) test-dir-source test-dir-destination test-dir-destination-chint
for s in ./test/conf/sources/*; do \
CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} daily "$$(basename "$$s")"; \
test "$$(ls -1 /tmp/ccollect/backup | wc -l)" -gt "0" || { cat ${TEST_LOG_FILE}; exit 1; }; \
done
CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} -a -v daily
test "$$(ls -1 /tmp/ccollect/backup | wc -l)" -gt "0" || { cat ${TEST_LOG_FILE}; exit 1; }
CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} -a -p daily
test "$$(ls -1 /tmp/ccollect/backup | wc -l)" -gt "0" || { cat ${TEST_LOG_FILE}; exit 1; }
@printf "\nFixed intervals test ended successfully\n"
test-interval-changing: $(CCOLLECT_SOURCE) test-dir-source test-dir-destination-chint
rm -rf /tmp/ccollect/backup-chint/*
test "$$(ls -1 /tmp/ccollect/backup-chint | wc -l)" -eq "0" || { cat ${TEST_LOG_FILE}; exit 1; }
printf "3" > ./test/conf/sources/local-with-interval/intervals/daily
for x in 1 2 3 4 5; do CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} daily local-with-interval; done
test "$$(ls -1 /tmp/ccollect/backup-chint | wc -l)" -eq "4" || { cat ${TEST_LOG_FILE}; exit 1; }
printf "5" > ./test/conf/sources/local-with-interval/intervals/daily
for x in 1 2 3 4 5 6 7; do CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} daily local-with-interval; done
test "$$(ls -1 /tmp/ccollect/backup-chint | wc -l)" -eq "6" || { cat ${TEST_LOG_FILE}; exit 1; }
printf "4" > ./test/conf/sources/local-with-interval/intervals/daily
for x in 1 2 3 4 5 6; do CCOLLECT_CONF=./test/conf ./ccollect -l ${TEST_LOG_FILE} daily local-with-interval; done
test "$$(ls -1 /tmp/ccollect/backup-chint | wc -l)" -eq "5" || { cat ${TEST_LOG_FILE}; exit 1; }
printf "3" > ./test/conf/sources/local-with-interval/intervals/daily
@printf "\nInterval changing test ended successfully\n"
test: test-fixed-intervals test-interval-changing
test -f "${TEST_LOG_FILE}"
@printf "\nTests ended successfully\n"

View File

@ -45,8 +45,8 @@ TMP="$(mktemp "/tmp/${__myname}.XXXXXX")"
export TMP
CONTROL_PIPE="/tmp/${__myname}-control-pipe"
VERSION="2.7"
RELEASE="2019-11-14"
VERSION="2.10"
RELEASE="2020-08-26"
HALF_VERSION="ccollect ${VERSION}"
FULL_VERSION="ccollect ${VERSION} (${RELEASE})"
@ -79,7 +79,7 @@ lock_flock()
# $1 = source to backup
# shellcheck disable=SC2059
lockfile="${LOCKDIR}/$(printf "${LOCKFILE_PATTERN}" "$1")"
eval "exec ${LOCKFD}> ${lockfile}"
eval "exec ${LOCKFD}> '${lockfile}'"
flock -n ${LOCKFD} && return 0 || return 1
}
@ -469,7 +469,7 @@ fi
if [ "${PARALLEL}" ]; then
mkfifo "${CONTROL_PIPE}"
# fd 5 is tied to control pipe
eval "exec 5<>${CONTROL_PIPE}"
eval "exec 5<>'${CONTROL_PIPE}'"
TRAPFUNC="${TRAPFUNC}; rm -f \"${CONTROL_PIPE}\""
# shellcheck disable=SC2064
trap "${TRAPFUNC}" 0 1 2 15
@ -767,20 +767,27 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
_techo "Using ${oldest_bak} for destination dir ${destination_dir}"
if mv "${oldest_bak}" "${destination_dir}"; then
# Touch dest dir so it is not sorted wrong in listings below.
touch "${destination_dir}"
ls_rm_exclude=$(basename "${destination_dir}")
# We have something to remove only if count > interval.
remove="$((count - c_interval))"
else
_techo_err "Renaming oldest backup ${oldest_bak} to ${destination_dir} failed, removing it."
remove="$((count - c_interval + 1))"
ls_rm_exclude=""
fi
if [ "${remove}" -gt 0 ]; then
_techo "Removing ${remove} backup(s)..."
# shellcheck disable=SC2010
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed"
if [ -z "${ls_rm_exclude}" ]; then
# shellcheck disable=SC2010
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed"
else
# shellcheck disable=SC2010
ls -${TSORT}1r | grep -v "${ls_rm_exclude}" | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed"
fi
delete_from_file "${TMP}" &
fi
@ -817,6 +824,11 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
rsync "$@" "${source}" "${destination_dir}"; ret=$?
_techo "Finished backup (rsync return code: $ret)."
#
# export rsync return code, might be useful in post_exec
#
export rsync_return_code=$ret
#
# Set modification time (mtime) to current time, if sorting by mtime is enabled
#
@ -849,6 +861,16 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
_techo "Warning: rsync failed with return code $ret."
fi
#
# Create symlink to newest backup
#
# shellcheck disable=SC2010
latest_dir="$(ls -${TSORT}p1 "${ddir}" | grep '/$' | head -n 1)" || \
_exit_err "Failed to list content of ${ddir}."
ln -snf "${ddir}/${latest_dir}" "${ddir}/current" || \
_exit_err "Failed to create 'current' symlink."
#
# post_exec
#

View File

@ -1,7 +1,7 @@
ccollect - Installing, Configuring and Using
============================================
Nico Schottelius <nico-ccollect__@__schottelius.org>
2.7, for ccollect 2.7, Initial Version from 2006-01-13
2.10, for ccollect 2.10, Initial Version from 2006-01-13
:Author Initials: NS

1
doc/changes/2.10 Normal file
View File

@ -0,0 +1 @@
* Add 'current' symlink to backup destinations (Steffen Zieger)

1
doc/changes/2.8 Normal file
View File

@ -0,0 +1 @@
* Fix excluding destination dir from removal

1
doc/changes/2.9 Normal file
View File

@ -0,0 +1 @@
* Make rsync return code available in post_exec (Steffen Zieger)

1
doc/changes/next Normal file
View File

@ -0,0 +1 @@
* Fix 'current' symlink (Jun Futagawa)

View File

View File

View File

@ -0,0 +1 @@
5

View File

@ -0,0 +1 @@
4

View File

@ -0,0 +1 @@
4

View File

@ -0,0 +1 @@
2

3
test/conf/defaults/post_exec Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
echo 'General post_exec executed.'

3
test/conf/defaults/pre_exec Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
echo 'General pre__exec executed.'

View File

@ -0,0 +1 @@
.git

View File

View File

View File

View File

@ -0,0 +1 @@
/tmp/ccollect/backup

View File

@ -0,0 +1 @@
.git

View File

@ -0,0 +1 @@
/tmp/ccollect/source

View File

@ -0,0 +1 @@
/tmp/ccollect/backup

View File

@ -0,0 +1 @@
.git

View File

@ -0,0 +1 @@
/tmp/ccollect/source

View File

@ -0,0 +1 @@
/tmp/ccollect/backup-chint

View File

@ -0,0 +1 @@
.git

View File

@ -0,0 +1 @@
3

View File

@ -0,0 +1 @@
/tmp/ccollect/source

View File

@ -0,0 +1 @@
/tmp/ccollect/backup

View File

@ -0,0 +1 @@
.git

View File

View File

@ -0,0 +1 @@
/tmp/ccollect/source

View File

@ -0,0 +1 @@
/tmp/ccollect/backup

View File

@ -0,0 +1 @@
.git

View File

@ -0,0 +1 @@
/tmp/ccollect/source

View File

@ -0,0 +1 @@
/tmp/ccollect/backup

View File

@ -0,0 +1 @@
.git

View File

@ -0,0 +1 @@
/tmp/ccollect/source

View File

View File

View File

@ -0,0 +1 @@
/tmp/ccollect/backup

View File

@ -0,0 +1,5 @@
#!/bin/cat
######################################################################
Source post_exec executed.
######################################################################

View File

@ -0,0 +1,5 @@
#!/bin/cat
######################################################################
Source pre_exec executed.
######################################################################

View File

@ -0,0 +1 @@
/tmp/ccollect/source

View File

@ -1,18 +0,0 @@
#!/bin/sh
host="home.schottelius.org"
host=""
set -x
pcmd()
{
echo "$#", "$@"
if [ "$host" ]; then
ssh "$host" "$@"
else
$@
fi
}
#pcmd ls /
#pcmd cd /; ls "/is not there"
pcmd cd / && ls

View File

@ -1 +0,0 @@
CCOLLECT_CONF=./conf ./ccollect.sh daily -v local1

View File

@ -1 +0,0 @@
CCOLLECT_CONF=./conf ./ccollect.sh daily -v remote1

View File

@ -1,23 +0,0 @@
#!/bin/sh
ls /surely-not-existent$$ 2>/dev/null
if [ "$?" -ne 0 ]; then
echo "$?"
fi
ls /surely-not-existent$$ 2>/dev/null
ret=$?
if [ "$ret" -ne 0 ]; then
echo "$ret"
fi
# if is true, ls is fales
if [ "foo" = "foo" ]; then
ls /surely-not-existent$$ 2>/dev/null
fi
# but that's still the return of ls and not of fi
echo $?

View File

@ -1,29 +0,0 @@
#!/bin/sh
#
# 2009 Nico Schottelius (nico-ccollect at schottelius.org)
#
# This file is part of ccollect.
#
# ccollect is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ccollect is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ccollect. If not, see <http://www.gnu.org/licenses/>.
#
#
# Test the ccollect tools suite
#
set -x
tmp="$(mktemp /tmp/ccollect-tools.XXXXXXXXXXX)"
rm -rf "${tmp}"

View File

@ -1,44 +0,0 @@
#!/bin/sh
#
# Nico Schottelius <nico-linux //@// schottelius.org>
# Date: 27-Jan-2007
# Last Modified: -
# Description:
#
ccollect=../ccollect.sh
testdir="$(dirname $0)/test-backups"
confdir="$(dirname $0)/test-config"
source="$(hostname)"
source_source="/tmp"
interval="taeglich"
# backup destination
mkdir -p "$testdir"
source_dest="$(cd "$testdir"; pwd -P)"
# configuration
mkdir -p "${confdir}/sources/${source}"
ln -s "$source_dest" "${confdir}/sources/${source}/destination"
echo "$source_source" > "${confdir}/sources/${source}/source"
touch "${confdir}/sources/${source}/summary"
touch "${confdir}/sources/${source}/verbose"
mkdir -p "${confdir}/defaults/intervals/"
echo 3 > "${confdir}/defaults/intervals/$interval"
# create backups
CCOLLECT_CONF="$confdir" "$ccollect" "$interval" -p -a
touch "${source_source}/$(date +%s)-$$.1982"
CCOLLECT_CONF="$confdir" "$ccollect" "$interval" -p -a
touch "${source_source}/$(date +%s)-$$.42"
CCOLLECT_CONF="$confdir" "$ccollect" "$interval" -p -a
du -sh "$testdir"
du -shl "$testdir"
echo "Delete $testdir and $confdir after test"