diff --git a/start.sh b/start.sh index c70d5db86b6cadf810a05a1c09a455aa5c07354e..b688914ecad51121093ccb5e0ad3354e4a531768 100755 --- a/start.sh +++ b/start.sh @@ -46,15 +46,19 @@ function mdb_load() { echo "Latest mdb file in backup: $bakData" # Restore data and config if LDAP_FORCE_RESTORE is true or newer backup exists or size is smaller then usual. echo "Comparing timestamps of $bakData and ${LDAP_MDB_DIR}/data.mdb" - if [[ ${LDAP_FORCE_RESTORE} = "true" ]] || [[ ${bakData} -nt ${LDAP_MDB_DIR}/data.mdb ]] \ - || du -sh ${LDAP_MDB_DIR}/data.mdb | grep -q 'M'; - then - if [[ ${LDAP_FORCE_RESTORE} = "true" ]]; then - echo "Force restore from ${bakData}" - else - du -sh ${LDAP_MDB_DIR}/data.mdb - echo -e "\nLoading most recent data and config..." - fi + RESTORE="false" + if [[ ${LDAP_FORCE_RESTORE} = "true" ]]; then + echo "Force restore flag is on." + RESTORE="true" + elif [[ -f ${LDAP_MDB_DIR}/data.mdb ]] && [[ ${bakData} -nt ${LDAP_MDB_DIR}/data.mdb ]]; then + echo "${LDAP_MDB_DIR}/data.mdb is newer." + RESTORE="true" + elif [[ -f ${LDAP_MDB_DIR}/data.mdb ]] && du -sh ${LDAP_MDB_DIR}/data.mdb | grep -q 'M'; then + echo "$(du -sh ${LDAP_MDB_DIR}/data.mdb) size is too small." + RESTORE="true" + fi + if [[ ${RESTORE} = "true" ]]; then + echo -e "\nLoading most recent data and config from ${bakData}..." find ${LDAP_MDB_DIR} -type f -name '*.mdb' -delete stat --format "Restoring snapshot '%n' modified on %y" ${bakData} cp -v ${bakData} ${LDAP_MDB_DIR}/data.mdb