Improve script compatibility by replacing PCRE grep with awk (resulting in overall nicer code)

This commit is contained in:
Janek Bevendorff 2014-10-05 19:38:21 +02:00
parent 9705fa78dc
commit f8c24cb457
1 changed files with 2 additions and 3 deletions

View File

@ -43,15 +43,14 @@ for home_dir in "${BACKUP_ROOT}"/*; do
config=$(cat "${BACKUP_ROOT}/etc/rsnapshot.global.conf")
# Get number of preceding increments
config=$(echo "${config}" | grep -P '^retain\t')
config=$(echo "${config}" | grep -oPz "retain\t+(\w+)\t+(\d+)\nretain\s+${1}\t+" | sed -n 1p)
config=$(echo "${config}" | awk '$1 == "retain" && $2 == "'${1}'" { print lastline } { lastline = $0 }')
preceding_name=$(echo "${config}" | awk '{ print $2 }')
preceding_number=$(($(echo "${config}" | awk ' { print $3 }') - 1))
# Continue if no proper preceding increment could be found
if [ "${preceding_name}" == "" ] ||
[ ! -d "${home_dir}/${FILES_DIR}/${preceding_name}.${preceding_number}" ]; then
echo "Not rotating ${1}"
echo "Not enough preceding increments found, not rotating ${1}"
continue
fi