Skip to content

Commit

Permalink
Merge pull request bareos#2122
Browse files Browse the repository at this point in the history
stored: list all devices if device is invalid/missing
  • Loading branch information
BareosBot authored Feb 10, 2025
2 parents a209450 + c2db5f1 commit 1eeb25f
Show file tree
Hide file tree
Showing 43 changed files with 107 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- openssl: unify ssl error logging [PR #2078]
- Inherit RunScript elements between JobDef resources [PR #2097]
- python-bareos: Add missing dh-python build dep [PR #2130]
- stored: list all devices if device is invalid/missing [PR #2122]

[PR #2039]: https://github.com/bareos/bareos/pull/2039
[PR #2040]: https://github.com/bareos/bareos/pull/2040
Expand All @@ -49,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[PR #2109]: https://github.com/bareos/bareos/pull/2109
[PR #2111]: https://github.com/bareos/bareos/pull/2111
[PR #2116]: https://github.com/bareos/bareos/pull/2116
[PR #2122]: https://github.com/bareos/bareos/pull/2122
[PR #2130]: https://github.com/bareos/bareos/pull/2130
[PR #2132]: https://github.com/bareos/bareos/pull/2132
[PR #2153]: https://github.com/bareos/bareos/pull/2153
Expand Down
15 changes: 12 additions & 3 deletions core/src/stored/bcopy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2002-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2024 Bareos GmbH & Co. KG
Copyright (C) 2013-2025 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 @@ -149,7 +149,6 @@ int main(int argc, char* argv[])
"(either as name of a Bareos Storage Daemon Device resource "
"or identical to the "
"Archive Device in a Bareos Storage Daemon Device resource).")
->required()
->type_name(" ");

std::string output_archive;
Expand All @@ -159,7 +158,6 @@ int main(int argc, char* argv[])
"(either as name of a Bareos Storage Daemon Device resource "
"or identical to the "
"Archive Device in a Bareos Storage Daemon Device resource).")
->required()
->type_name(" ");

ParseBareosApp(bcopy_app, argc, argv);
Expand All @@ -173,6 +171,17 @@ int main(int argc, char* argv[])
my_config = InitSdConfig(configFile.c_str(), M_CONFIG_ERROR);
ParseSdConfig(configFile.c_str(), M_CONFIG_ERROR);

if (input_archive.empty()) {
printf(T_("Missing input device. %sNothing done.\n"),
AvailableDevicesListing().c_str());
return BEXIT_CLI_PARSING_ERROR;
} else if (output_archive.empty()) {
printf(T_("Missing output device. %sNothing done.\n"),
AvailableDevicesListing().c_str());
return BEXIT_CLI_PARSING_ERROR;
}


DirectorResource* director = nullptr;
if (!DirectorName.empty()) {
foreach_res (director, R_DIRECTOR) {
Expand Down
11 changes: 7 additions & 4 deletions core/src/stored/bextract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2024 Bareos GmbH & Co. KG
Copyright (C) 2013-2025 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 @@ -212,22 +212,25 @@ int main(int argc, char* argv[])
"Specify the input device name (either as name of a Bareos "
"Storage Daemon Device resource or identical to the Archive "
"Device in a Bareos Storage Daemon Device resource).")
->required()
->type_name(" ");

std::string directory_to_store_files;
bextract_app
.add_option("target-directory", directory_to_store_files,
"Specify directory where to store files.")
->required()
->type_name(" ");


ParseBareosApp(bextract_app, argc, argv);

my_config = InitSdConfig(configfile, M_CONFIG_ERROR);
ParseSdConfig(configfile, M_CONFIG_ERROR);

if (archive_device_name.empty()) {
printf(T_("Missing device. %sNothing done.\n"),
AvailableDevicesListing().c_str());
return BEXIT_CLI_PARSING_ERROR;
}

static DirectorResource* director = nullptr;
if (!DirectorName.empty()) {
foreach_res (director, R_DIRECTOR) {
Expand Down
9 changes: 7 additions & 2 deletions core/src/stored/bls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2024 Bareos GmbH & Co. KG
Copyright (C) 2013-2025 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 @@ -210,14 +210,19 @@ int main(int argc, char* argv[])
"(either as name of a Bareos Storage Daemon Device resource "
"or identical to the "
"Archive Device in a Bareos Storage Daemon Device resource).")
->required()
->type_name(" ");

ParseBareosApp(bls_app, argc, argv);

my_config = InitSdConfig(configfile, M_CONFIG_ERROR);
ParseSdConfig(configfile, M_CONFIG_ERROR);

if (device_names.size() == 0) {
printf(T_("Missing input device. %sNothing done.\n"),
AvailableDevicesListing().c_str());
return BEXIT_CLI_PARSING_ERROR;
}

if (!DirectorName.empty()) {
foreach_res (director, R_DIRECTOR) {
if (bstrcmp(director->resource_name_, DirectorName.c_str())) { break; }
Expand Down
9 changes: 7 additions & 2 deletions core/src/stored/bscan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2001-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2024 Bareos GmbH & Co. KG
Copyright (C) 2013-2025 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 @@ -236,14 +236,19 @@ int main(int argc, char* argv[])
"Specify the input device name (either as name of a Bareos "
"Storage Daemon Device resource or identical to the Archive "
"Device in a Bareos Storage Daemon Device resource).")
->required()
->type_name(" ");

ParseBareosApp(bscan_app, argc, argv);

my_config = InitSdConfig(configfile, M_CONFIG_ERROR);
ParseSdConfig(configfile, M_CONFIG_ERROR);

if (device_name.empty()) {
printf(T_("Missing input device. %sNothing done.\n"),
AvailableDevicesListing().c_str());
return BEXIT_CLI_PARSING_ERROR;
}

DirectorResource* director = nullptr;
if (!DirectorName.empty()) {
foreach_res (director, R_DIRECTOR) {
Expand Down
9 changes: 7 additions & 2 deletions core/src/stored/btape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2024 Bareos GmbH & Co. KG
Copyright (C) 2013-2025 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 @@ -289,7 +289,6 @@ int main(int margc, char* margv[])
"Specify the input device name (either as name of a Bareos "
"Storage Daemon Device resource or identical to the Archive "
"Device in a Bareos Storage Daemon Device resource).")
->required()
->type_name(" ");

btape_app.add_option_group("Interactive commands",
Expand All @@ -309,6 +308,12 @@ int main(int margc, char* margv[])
my_config = InitSdConfig(configfile, M_CONFIG_ERROR);
ParseSdConfig(configfile, M_CONFIG_ERROR);

if (archive_name.empty()) {
printf(T_("Missing input device. %sNothing done.\n"),
AvailableDevicesListing().c_str());
return BEXIT_CLI_PARSING_ERROR;
}

DirectorResource* director = nullptr;
if (!DirectorName.empty()) {
foreach_res (director, R_DIRECTOR) {
Expand Down
28 changes: 25 additions & 3 deletions core/src/stored/butil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2024 Bareos GmbH & Co. KG
Copyright (C) 2013-2025 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 @@ -44,6 +44,8 @@
#include "lib/parse_conf.h"
#include "include/jcr.h"

#include <algorithm>

namespace storagedaemon {

/* Forward referenced functions */
Expand Down Expand Up @@ -123,6 +125,25 @@ JobControlRecord* SetupJcr(const char* name,
return jcr;
}

std::string AvailableDevicesListing()
{
std::vector<std::string> devices;
for (BareosResource* resource = nullptr;
(resource = my_config->GetNextRes(R_DEVICE, resource));) {
DeviceResource* device = dynamic_cast<DeviceResource*>(resource);
std::string device_str;
device_str += " \"";
device_str += device->resource_name_;
device_str += "\" (";
device_str += device->archive_device_string;
device_str += ")\n";
devices.emplace_back(std::move(device_str));
}
std::sort(devices.begin(), devices.end());
std::string devices_str = "Available Devices:\n";
for (const std::string& device : devices) { devices_str += device; }
return devices_str;
}
/**
* Setup device, jcr, and prepare to access device.
* If the caller wants read access, acquire the device, otherwise,
Expand Down Expand Up @@ -170,8 +191,9 @@ static bool setup_to_access_device(DeviceControlRecord* dcr,
}

if ((device_resource = find_device_res(dev_name, readonly)) == NULL) {
Jmsg2(jcr, M_FATAL, 0, T_("Cannot find device \"%s\" in config file %s.\n"),
dev_name, configfile);
Jmsg2(jcr, M_FATAL, 0,
T_("Cannot find device \"%s\" in config file %s.\n%s"), dev_name,
configfile, AvailableDevicesListing().c_str());
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/stored/butil.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2018-2022 Bareos GmbH & Co. KG
Copyright (C) 2018-2025 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 @@ -44,6 +44,7 @@ JobControlRecord* SetupJcr(const char* name,
const std::string& VolumeName,
bool readonly);
void DisplayTapeErrorStatus(JobControlRecord* jcr, Device* dev);
std::string AvailableDevicesListing();

} /* namespace storagedaemon */

Expand Down
4 changes: 1 addition & 3 deletions docs/manuals/source/include/autogenerated/usage/bcopy.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
Usage: bcopy [OPTIONS] input-archive output-archive
Usage: bcopy [OPTIONS] [input-archive] [output-archive]

Positionals:
input-archive
REQUIRED
Specify the input device name (either as name of a Bareos Storage
Daemon Device resource or identical to the Archive Device in a Bareos
Storage Daemon Device resource).

output-archive
REQUIRED
Specify the output device name (either as name of a Bareos Storage
Daemon Device resource or identical to the Archive Device in a Bareos
Storage Daemon Device resource).
Expand Down
4 changes: 1 addition & 3 deletions docs/manuals/source/include/autogenerated/usage/bextract.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
Usage: bextract [OPTIONS] bareos-archive-device-name target-directory
Usage: bextract [OPTIONS] [bareos-archive-device-name] [target-directory]

Positionals:
bareos-archive-device-name
REQUIRED
Specify the input device name (either as name of a Bareos Storage
Daemon Device resource or identical to the Archive Device in a Bareos
Storage Daemon Device resource).

target-directory
REQUIRED
Specify directory where to store files.


Expand Down
3 changes: 1 addition & 2 deletions docs/manuals/source/include/autogenerated/usage/bls.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Usage: bls [OPTIONS] device-names...
Usage: bls [OPTIONS] [device-names...]

Positionals:
device-names ...
REQUIRED
Specify the input device name (either as name of a Bareos Storage
Daemon Device resource or identical to the Archive Device in a Bareos
Storage Daemon Device resource).
Expand Down
3 changes: 1 addition & 2 deletions docs/manuals/source/include/autogenerated/usage/bscan.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Usage: bscan [OPTIONS] device_name
Usage: bscan [OPTIONS] [device_name]

Positionals:
device_name
REQUIRED
Specify the input device name (either as name of a Bareos Storage
Daemon Device resource or identical to the Archive Device in a Bareos
Storage Daemon Device resource).
Expand Down
3 changes: 1 addition & 2 deletions docs/manuals/source/include/autogenerated/usage/btape.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Usage: btape [OPTIONS] bareos-archive-device-name
Usage: btape [OPTIONS] [bareos-archive-device-name]

Positionals:
bareos-archive-device-name
REQUIRED
Specify the input device name (either as name of a Bareos Storage
Daemon Device resource or identical to the Archive Device in a Bareos
Storage Daemon Device resource).
Expand Down
4 changes: 2 additions & 2 deletions systemtests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2024 Bareos GmbH & Co. KG
# Copyright (C) 2019-2025 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 @@ -33,7 +33,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
system:bareos-basic:bls-autoxflate
system:bareos-basic:bscan-autoxflate
system:bareos-basic:volume-recycling
system:bscan-bextract-bls-bcopy
system:bscan-bextract-bls-bcopy-btape
system:checkpoints:checkpoints-regular-backup
system:client-initiated
system:commandline-options
Expand Down
1 change: 1 addition & 0 deletions systemtests/environment.in
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export BAREOS_BSCAN_BINARY=$(dirname "@BSCAN_BINARY@")/$CMAKE_CONFIG_TYPE/$(base
export BAREOS_BLS_BINARY=$(dirname "@BLS_BINARY@")/$CMAKE_CONFIG_TYPE/$(basename "@BLS_BINARY@")
export BAREOS_BCONSOLE_BINARY=$(dirname "@BCONSOLE_UNSAFE_BINARY@")/$CMAKE_CONFIG_TYPE/$(basename "@BCONSOLE_UNSAFE_BINARY@")
export BAREOS_BEXTRACT_BINARY=$(dirname "@BEXTRACT_BINARY@")/$CMAKE_CONFIG_TYPE/$(basename "@BEXTRACT_BINARY@")
export BAREOS_BTAPE_BINARY=$(dirname "@BTAPE_BINARY@")/$CMAKE_CONFIG_TYPE/$(basename "@BTAPE_BINARY@")
export BAREOS_DBCHECK_BINARY=$(dirname "@BAREOS_DBCHECK_BINARY@")/$CMAKE_CONFIG_TYPE/$(basename "@BAREOS_DBCHECK_BINARY@")
export BAREOS_BCOPY_BINARY=$(dirname "@BCOPY_BINARY@")/$CMAKE_CONFIG_TYPE/$(basename "@BCOPY_BINARY@")
export BAREOS_BDEDUPESTIMATE_BINARY=$(dirname "@BDEDUPESTIMATE_BINARY@")/$CMAKE_CONFIG_TYPE/$(basename "@BDEDUPESTIMATE_BINARY@")
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-2024 Bareos GmbH & Co. KG
# Copyright (C) 2021-2025 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 @@ -30,7 +30,7 @@ add_subdirectory(bareos-acl)
add_subdirectory(bconsole-basic)
add_subdirectory(bconsole-pam)
add_subdirectory(block-size)
add_subdirectory(bscan-bextract-bls-bcopy)
add_subdirectory(bscan-bextract-bls-bcopy-btape)
add_subdirectory(catalog)
add_subdirectory(checkpoints)
add_subdirectory(chflags)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2021-2022 Bareos GmbH & Co. KG
# Copyright (C) 2021-2025 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
Loading

0 comments on commit 1eeb25f

Please sign in to comment.