Skip to content

Commit

Permalink
Merge pull request #1106
Browse files Browse the repository at this point in the history
Fix stale volumes/devices in bareos-sd after failure to acquire a read device on MAC jobs
  • Loading branch information
pstorz committed Mar 10, 2022
2 parents 18797e4 + b0f0413 commit 30ed31f
Show file tree
Hide file tree
Showing 41 changed files with 247 additions and 141 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- webui: fix deprecated notice required param follows optional param [PR #1097]
- webui: fix uncaught TypeError if node.data is null [PR #1087]
- core cats: Add DROP VIEWS instruction in drop_bareos_table script [PR #1092]
- Don't keep volume open after acquiring a read-storage failed in migrate/copy/virtual full [PR #1106]

### Added
- Python plugins: add default module_path to search path [PR #1038]
Expand Down
6 changes: 4 additions & 2 deletions core/src/dird/migrate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1495,11 +1495,13 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
WaitForStorageDaemonTermination(jcr);
WaitForStorageDaemonTermination(mig_jcr);
jcr->setJobStatus(jcr->impl->SDJobStatus);
mig_jcr->db_batch->WriteBatchFileRecords(mig_jcr);
if (mig_jcr->batch_started) {
mig_jcr->db_batch->WriteBatchFileRecords(mig_jcr);
}
} else {
WaitForStorageDaemonTermination(jcr);
jcr->setJobStatus(jcr->impl->SDJobStatus);
jcr->db_batch->WriteBatchFileRecords(jcr);
if (jcr->batch_started) { jcr->db_batch->WriteBatchFileRecords(jcr); }
}

bail_out:
Expand Down
9 changes: 5 additions & 4 deletions core/src/stored/mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2006-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -686,16 +686,17 @@ bool DoMacRun(JobControlRecord* jcr)
job_elapsed / 3600, job_elapsed % 3600 / 60, job_elapsed % 60,
edit_uint64_with_suffix(jcr->JobBytes / job_elapsed, ec1));

// Release the device -- and send final Vol info to DIR
ReleaseDevice(jcr->impl->dcr);

// send final Vol info to DIR
if (!ok || JobCanceled(jcr)) {
DiscardAttributeSpool(jcr);
} else {
CommitAttributeSpool(jcr);
}
}

if (!jcr->impl->remote_replicate && jcr->impl->dcr) {
if (!ReleaseDevice(jcr->impl->dcr)) { ok = false; }
}
if (jcr->impl->read_dcr) {
if (!ReleaseDevice(jcr->impl->read_dcr)) { ok = false; }
}
Expand Down
4 changes: 2 additions & 2 deletions systemtests/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2021-2021 Bareos GmbH & Co. KG
# Copyright (C) 2021-2022 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -31,8 +31,8 @@ add_subdirectory(chflags)
add_subdirectory(client-initiated)
add_subdirectory(config-dump)
add_subdirectory(config-syntax-crash)
add_subdirectory(copy)
add_subdirectory(copy-archive-job)
add_subdirectory(copy-bscan)
add_subdirectory(copy-remote-bscan)
add_subdirectory(dbcopy-mysql-postgresql)
add_subdirectory(deprecation)
Expand Down
132 changes: 0 additions & 132 deletions systemtests/tests/copy-bscan/testrunner

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2021-2021 Bareos GmbH & Co. KG
# Copyright (C) 2021-2022 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand All @@ -19,3 +19,26 @@

get_filename_component(BASENAME ${CMAKE_CURRENT_BINARY_DIR} NAME)
create_systemtest(${SYSTEMTEST_PREFIX} ${BASENAME})

set_tests_properties(
system:copy:01-backup PROPERTIES FIXTURES_SETUP "system:copy:01-backup"
FIXTURES_REQUIRED "system:copy-fixture"
)
set_tests_properties(
system:copy:02-copy
PROPERTIES FIXTURES_SETUP "system:copy:02-copy" FIXTURES_REQUIRED
"system:copy:01-backup;system:copy-fixture"
)
set_tests_properties(
system:copy:03-impossible-copy
PROPERTIES FIXTURES_SETUP "system:copy:03-impossible-copy" FIXTURES_REQUIRED
"system:copy:02-copy;system:copy:01-backup;system:copy-fixture"
)
set_tests_properties(
system:copy:04-bscan
PROPERTIES
FIXTURES_SETUP
"system:copy:04-bscan"
FIXTURES_REQUIRED
"system:copy:03-impossible-copy;system:copy:02-copy;system:copy:01-backup;system:copy-fixture"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Storage {
Name = NoSuchStorage
Address = localhost
Password = "does not matter"
Device = NoSuchDevice
Media Type = NoSuchType
}
46 changes: 46 additions & 0 deletions systemtests/tests/copy/testrunner-01-backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
set -e
set -o pipefail
set -u

TestName=01-backup

#shellcheck source=../environment.in
. ./environment

#shellcheck source=../scripts/functions
. "${rscripts}"/functions

log="$tmp/$TestName.log"

check_log() {
if ! grep -q "$@" "$log"; then
echo "'$*' not found in $log" >&2
estat=1
fi
}

setup_data

start_test

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out /dev/null
messages
@$out $log
label volume=TestVolume001 storage=File pool=Full
run job=backup-bareos-fd yes
wait
update volume=TestVolume001 volstatus=Used
messages
quit
END_OF_DATA

run_bconsole "$tmp/bconcmds"

check_for_zombie_jobs storage=File

check_log -F 'Catalog record for Volume "TestVolume001", Slot 0 successfully created.'
check_log 'Termination:.*Backup OK'

end_test
43 changes: 43 additions & 0 deletions systemtests/tests/copy/testrunner-02-copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
set -e
set -o pipefail
set -u

TestName=02-copy

#shellcheck source=../environment.in
. ./environment

#shellcheck source=../scripts/functions
. "${rscripts}"/functions

log="$tmp/$TestName.log"

check_log() {
if ! grep -q "$@" "$log"; then
echo "'$*' not found in $log" >&2
estat=1
fi
}

start_test

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out /dev/null
messages
@$out $log
label volume=TestCopyVolume001 storage=File2 pool=FullCopy
run copy yes
wait
messages
quit
END_OF_DATA

run_bconsole "$tmp/bconcmds"

check_for_zombie_jobs storage=File

check_log -F 'Catalog record for Volume "TestCopyVolume001", Slot 0 successfully created.'
check_log 'Termination:.*Copying OK'

end_test
56 changes: 56 additions & 0 deletions systemtests/tests/copy/testrunner-03-impossible-copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
set -e
set -o pipefail
set -u

TestName=03-impossible-copy

#shellcheck source=../environment.in
. ./environment

#shellcheck source=../scripts/functions
. "${rscripts}"/functions

log="$tmp/$TestName.log"

check_logged() {
if ! grep -q "$@" "$log"; then
echo "'$*' not found in $log" >&2
estat=1
fi
}
check_not_logged() {
if grep -q "$@" "$log"; then
echo "'$*' found in $log" >&2
estat=1
fi
}

start_test

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out /dev/null
messages
@$out $log
sqlquery
UPDATE Media SET mediatype = 'NoSuchType' WHERE volumename = 'TestVolume001';
run copy yes
wait
messages
status storage=File2
quit
END_OF_DATA

run_bconsole "$tmp/bconcmds"

check_for_zombie_jobs storage=File

check_logged -F 'Changing read device. Want Media Type="NoSuchType"'
check_logged -F '*** Copying Error ***'
# check if there is a stale volume in the storage's volume list
check_not_logged -F 'on device "FileStorage2" (storage)'

end_test

0 comments on commit 30ed31f

Please sign in to comment.