fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
Loading...
Searching...
No Matches
BackupManager.cpp
1/*
2 * MIT License
3 *
4 * Copyright (c) 2026 Adriano dos Santos Fernandes
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#include "BackupManager.h"
26#include "Client.h"
27
28using namespace fbcpp;
29using namespace fbcpp::impl;
30
32{
33 StatusWrapper statusWrapper{getClient()};
34 auto builder =
35 fbUnique(getClient().getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::SPB_START, nullptr, 0));
36 builder->insertTag(&statusWrapper, isc_action_svc_backup);
37 builder->insertString(&statusWrapper, isc_spb_dbname, options.getDatabase().c_str());
38
39 for (const auto& backupFile : options.getBackupFiles())
40 {
41 builder->insertString(&statusWrapper, isc_spb_bkp_file, backupFile.path.c_str());
42
43 if (backupFile.length)
44 addSpbInt(builder.get(), &statusWrapper, isc_spb_bkp_length, *backupFile.length, "Backup file length");
45 }
46
47 if (options.getVerboseOutput())
48 builder->insertTag(&statusWrapper, isc_spb_verbose);
49
50 if (const auto parallelWorkers = options.getParallelWorkers())
51 builder->insertInt(&statusWrapper, isc_spb_bkp_parallel_workers, static_cast<int>(*parallelWorkers));
52
53 const auto buffer = builder->getBuffer(&statusWrapper);
54 const auto length = builder->getBufferLength(&statusWrapper);
55
56 startAction(std::vector<std::uint8_t>(buffer, buffer + length));
57 waitForCompletion(options.getVerboseOutput());
58}
59
61{
62 StatusWrapper statusWrapper{getClient()};
63 auto builder =
64 fbUnique(getClient().getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::SPB_START, nullptr, 0));
65 builder->insertTag(&statusWrapper, isc_action_svc_restore);
66
67 for (const auto& databaseFile : options.getDatabaseFiles())
68 {
69 builder->insertString(&statusWrapper, isc_spb_dbname, databaseFile.path.c_str());
70
71 if (databaseFile.length)
72 addSpbInt(builder.get(), &statusWrapper, isc_spb_res_length, *databaseFile.length, "Database file length");
73 }
74
75 for (const auto& backupFile : options.getBackupFiles())
76 builder->insertString(&statusWrapper, isc_spb_bkp_file, backupFile.c_str());
77
78 builder->insertInt(
79 &statusWrapper, isc_spb_options, options.getReplace() ? isc_spb_res_replace : isc_spb_res_create);
80
81 if (options.getVerboseOutput())
82 builder->insertTag(&statusWrapper, isc_spb_verbose);
83
84 if (const auto parallelWorkers = options.getParallelWorkers())
85 builder->insertInt(&statusWrapper, isc_spb_res_parallel_workers, static_cast<int>(*parallelWorkers));
86
87 const auto buffer = builder->getBuffer(&statusWrapper);
88 const auto length = builder->getBufferLength(&statusWrapper);
89
90 startAction(std::vector<std::uint8_t>(buffer, buffer + length));
91 waitForCompletion(options.getVerboseOutput(), true);
92}
void restore(const RestoreOptions &options)
Runs a restore operation using the provided options.
void backup(const BackupOptions &options)
Runs a backup operation using the provided options.
Represents options used to run a backup operation through the service manager.
const std::vector< BackupFileSpec > & getBackupFiles() const
Returns the configured backup file specifications.
const std::string & getDatabase() const
Returns the database path to be backed up.
const ServiceManager::VerboseOutput & getVerboseOutput() const
Returns the verbose output callback.
const std::optional< std::uint32_t > & getParallelWorkers() const
Returns the requested number of parallel workers.
Represents options used to run a restore operation through the service manager.
bool getReplace() const
Returns whether the target database should be replaced.
const std::optional< std::uint32_t > & getParallelWorkers() const
Returns the requested number of parallel workers.
const ServiceManager::VerboseOutput & getVerboseOutput() const
Returns the verbose output callback.
const std::vector< DatabaseFileSpec > & getDatabaseFiles() const
Returns the configured database file specifications.
const std::vector< std::string > & getBackupFiles() const
Returns the backup file paths.
Client & getClient() noexcept
Returns the Client object reference used to create this ServiceManager object.
fb-cpp namespace.
Definition Attachment.h:42
FbUniquePtr< T > fbUnique(T *obj) noexcept
Creates a unique pointer for a Firebird disposable object.
Definition SmartPtrs.h:59