bontmia | 61 +++++++++++++++++-------------------------------------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/bontmia b/bontmia index a1d9fc0..dba05a8 100755 --- a/bontmia +++ b/bontmia @@ -177,29 +177,6 @@ EOF } -unlock_destination() -{ - rm -f "${tmpdir}/is_running.lock" -} - - -lock_destination() -{ - # Ensure that there is no other bontmia running against the same destination - touch /tmp/bontmia_lock_file.$$ - echo "no" | mv -i /tmp/bontmia_lock_file.$$ "${tmpdir}"/is_running.lock 2>&1 | \ - grep "overwrite" >/dev/null 2>&1 && { - echo "Bontmia is already doing a backup on this tmpdir:" - echo " ${tmpdir}" - echo - echo " If you are sure this is false you can manually remove the lockfile:" - echo " ${tmpdir}/is_running.lock" - echo - exit 1 - } -} - - full_name() { host="${1}"; if host ${host} | grep "domain name pointer" >/dev/null; then @@ -238,7 +215,6 @@ filter_template() date -d "${the_date}" "+%Y/%m/%d/${the_clock}@${template_name}@${attribute}" || { echo "Could not read the time of a previous backup" echo "Please email the author" - unlock_destination exit 1 } done | egrep "@.*@${grep_value}" | sort -r | ${sort} | tail -${last_number} @@ -267,7 +243,6 @@ make_hard-link_copy_of_last_backup() echo " (${last_backup})" if test "x${dryrun}" == "xno"; then mkdir -p "${tmpdir}/unfinished_backup/${this_backup}" || { - unlock_destination exit 1 } cp -lR "${last_backup}/"* "${tmpdir}/unfinished_backup/${this_backup}" >/dev/null 2>&1 || { @@ -280,7 +255,6 @@ make_hard-link_copy_of_last_backup() echo "No previous backup detected, will start with an empty replication" if test "x${dryrun}" == "xno"; then mkdir -p "${tmpdir}/unfinished_backup/$this_backup" || { - unlock_destination exit 1 } fi @@ -297,11 +271,9 @@ moving_complete_backup_into_archive() if test "x$dryrun" == "xno"; then mkdir -p "$backup_destination/$this_backup" || { - unlock_destination exit 1 } mv "$tmpdir/unfinished_backup/$this_backup/"* "$backup_destination/$this_backup/" || { - unlock_destination exit 1 } fi @@ -313,7 +285,6 @@ do_the_backup_exist() if test -e "$backup_destination/$1"; then echo "The backup destination already exist" echo "This means that there is less than a minute since the last backup" - unlock_destination exit 1 fi } @@ -535,7 +506,6 @@ check_program() type -a "$program" >/dev/null 2>&1 } || { echo "You need $program installed and in the path" echo "Aborting" - unlock_destination exit 1 } } @@ -551,14 +521,12 @@ check_for_programs() echo "'--mindepth' options" echo "You might not have the GNU version of 'find'" echo "Aborting" - unlock_destination exit 1 } date -d 20030303 >/dev/null 2>/dev/null || { echo "'date' on your system does not support the '--date' option" echo "You might not have the GNU version of 'date'" echo "Aborting" - unlock_destination exit 1 } check_program cp @@ -566,14 +534,12 @@ check_for_programs() echo "Could not create a temporary file on /tmp" echo "Please make sure that /tmp is writable" echo "Aborting" - unlock_destination exit 1 } cp -l /tmp/bontmia_test_cp_file.$$ /tmp/bontmia_test_cp_file.$$.2 >/dev/null 2>&1 || { echo "cp on your system does not support the -l option" echo "You might not have the GNU version of 'cp'" echo "Aborting" - unlock_destination exit 1 } rm -f /tmp/bontmia_test_cp_file.$$ /tmp/bontmia_test_cp_file.$$.2 @@ -726,15 +692,22 @@ bdirmatch=$( echo "bdirmatch: $bdirmatch" -lock_destination - -if test "x$backup_dirs" != x; then - make_backup -fi +( + flock -n 9 + if [ $? != "0" ]; then + echo "Bontmia is already doing a backup on this tmpdir:" + echo " ${tmpdir}" + exit 1 + fi -if test "x$do_del_old" == xyes; then - delete_old_backup -fi + if test "x$backup_dirs" != x; then + make_backup + fi + + if test "x$do_del_old" == xyes; then + delete_old_backup + fi + + exit $exit_status +) 9> "${tmpdir}"/is_running.lock -unlock_destination -exit $exit_status