Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions src/burp/burp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,11 @@ int gbak(Firebird::UtilSvc* uSvc)
BURP_error(334, true, SafeArg() << in_sw_tab->in_sw_name);
tdgbl->gbl_sw_direct_io = true;
break;
case IN_SW_BURP_OVERWRITE:
if (tdgbl->gbl_sw_backup_overwrite)
BURP_error(334, true, SafeArg() << in_sw_tab->in_sw_name);
tdgbl->gbl_sw_backup_overwrite = true;
break;
case IN_SW_BURP_E:
if (!tdgbl->gbl_sw_compress)
BURP_error(334, true, SafeArg() << in_sw_tab->in_sw_name);
Expand Down Expand Up @@ -1162,21 +1167,23 @@ int gbak(Firebird::UtilSvc* uSvc)
Firebird::PathName expanded;
expandDatabaseName(file->fil_name, expanded, NULL);

const bool isSource = (file->fil_name.c_str() == file1);

for (file_list = file->fil_next; file_list;
file_list = file_list->fil_next)
{
if (file->fil_name == file_list->fil_name || expanded == file_list->fil_name)
{
BURP_error(9, true);
// msg 9 mutiple sources or destinations specified
}

Firebird::PathName expanded2;
expandDatabaseName(file_list->fil_name, expanded2, NULL);
if (file->fil_name == expanded2 || expanded == expanded2)

if (file->fil_name == file_list->fil_name || expanded == file_list->fil_name ||
file->fil_name == expanded2 || expanded == expanded2)
{
BURP_error(9, true);
// msg 9 mutiple sources or destinations specified
if (isSource)
BURP_error(11, true);
// msg 11 input and output have the same name. Disallowed.
else
BURP_error(9, true);
// msg 9 mutiple sources or destinations specified
}
}

Expand Down Expand Up @@ -2216,15 +2223,29 @@ static gbak_action open_files(const TEXT* file1,
{
Firebird::string nm = tdgbl->toSystem(fil->fil_name);
#ifdef WIN_NT
if ((fil->fil_fd = NT_tape_open(nm.c_str(), MODE_WRITE, CREATE_ALWAYS)) == INVALID_HANDLE_VALUE)
if ((fil->fil_fd = NT_tape_open(nm.c_str(), MODE_WRITE,
tdgbl->gbl_sw_backup_overwrite ? CREATE_ALWAYS : CREATE_NEW)) == INVALID_HANDLE_VALUE)
#else
const int wmode = MODE_WRITE | (tdgbl->gbl_sw_direct_io ? O_DIRECT : 0);
const int wmode = MODE_WRITE
| (tdgbl->gbl_sw_direct_io ? O_DIRECT : 0)
| (tdgbl->gbl_sw_backup_overwrite ? 0 : O_EXCL);
if ((fil->fil_fd = open(fil->fil_name.c_str(), wmode, open_mask)) == -1)
#endif // WIN_NT
{

BURP_error(65, false, fil->fil_name.c_str());
// msg 65 can't open backup file %s
#ifdef WIN_NT
if (GetLastError() == ERROR_FILE_EXISTS)
#else
if (errno == EEXIST)
#endif // WIN_NT
{
BURP_error(424, false, fil->fil_name.c_str());
// msg 424 backup file %s already exists, use -OVERWRITE to replace
}
else
{
BURP_error(65, false, fil->fil_name.c_str());
// msg 65 can't open backup file %s
}
flag = QUIT;
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/burp/burp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ class BurpGlobals : public Firebird::ThreadData, public GblPool
bool gbl_sw_mode_val;
bool gbl_sw_overwrite;
bool gbl_sw_direct_io;
bool gbl_sw_backup_overwrite;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd better reuse the existing gbl_sw_overwrite option. Backup and restore are mutually exclusive commands.

bool gbl_sw_zip;
const SCHAR* gbl_sw_keyholder;
const SCHAR* gbl_sw_crypt;
Expand Down
3 changes: 3 additions & 0 deletions src/burp/burpswi.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ inline constexpr int IN_SW_BURP_DIRECT_IO = 55; // direct IO for backup files

inline constexpr int IN_SW_BURP_SKIP_SCHEMA_DATA = 56; // skip data from schema
inline constexpr int IN_SW_BURP_INCLUDE_SCHEMA_DATA = 57; // backup data from schemas
inline constexpr int IN_SW_BURP_OVERWRITE = 58; // allow overwriting existing backup file

/**************************************************************************/

Expand Down Expand Up @@ -170,6 +171,8 @@ static inline constexpr Switches::in_sw_tab_t reference_burp_in_sw_table[] =
// msg 99: @1ONE_AT_A_TIME restore one relation at a time
{IN_SW_BURP_OL, isc_spb_bkp_old_descriptions, "OLD_DESCRIPTIONS", 0, 0, 0, false, true, 186, 2, NULL, boBackup},
// msg 186: @1OLD_DESCRIPTIONS save old style metadata descriptions
{IN_SW_BURP_OVERWRITE, 0, "OVERWRITE", 0, 0, 0, false, true, 423, 2, NULL, boBackup},
// msg 423: @1OV(ERWRITE) allow overwriting existing backup file(s)
{IN_SW_BURP_P, isc_spb_res_page_size, "PAGE_SIZE", 0, 0, 0, false, false, 101, 1, NULL, boRestore},
// msg 101: @1PAGE_SIZE override default page size
{IN_SW_BURP_PARALLEL_WORKERS, isc_spb_bkp_parallel_workers, "PARALLEL", 0, 0, 0, false, false, 406, 3, NULL, boGeneral},
Expand Down
27 changes: 24 additions & 3 deletions src/burp/mvol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,17 +1548,38 @@ static DESC next_volume( DESC handle, ULONG mode, bool full_buffer)
prompt_for_name(new_file, sizeof(new_file));

#ifdef WIN_NT
new_desc = NT_tape_open(new_file, mode, OPEN_ALWAYS);
if (mode == MODE_WRITE)
{
new_desc = NT_tape_open(new_file, mode,
tdgbl->gbl_sw_backup_overwrite ? CREATE_ALWAYS : CREATE_NEW);
}
else
new_desc = NT_tape_open(new_file, mode, OPEN_ALWAYS);
if (new_desc == INVALID_HANDLE_VALUE)
#else
ULONG mode2 = mode;
if (mode == MODE_WRITE && tdgbl->gbl_sw_direct_io)
mode2 |= O_DIRECT;
if (mode == MODE_WRITE)
{
if (tdgbl->gbl_sw_direct_io)
mode2 |= O_DIRECT;
if (!tdgbl->gbl_sw_backup_overwrite)
mode2 |= O_EXCL;
}

new_desc = open(new_file, mode2, open_mask);
if (new_desc < 0)
#endif // WIN_NT
{
#ifdef WIN_NT
if (mode == MODE_WRITE && GetLastError() == ERROR_FILE_EXISTS)
#else
if (mode == MODE_WRITE && errno == EEXIST)
#endif // WIN_NT
{
BURP_print(true, 424, new_file);
// msg 424 backup file %s already exists, use -OVERWRITE to replace
continue;
}
BURP_print(true, 222, new_file);
// msg 222 \n\nCould not open file name \"%s\"\n
continue;
Expand Down
2 changes: 2 additions & 0 deletions src/include/firebird/impl/msg/gbak.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,5 @@ FB_IMPL_MSG_NO_SYMBOL(GBAK, 419, "regular expression to skip schemas was already
FB_IMPL_MSG_NO_SYMBOL(GBAK, 420, "regular expression to include schemas was already set")
FB_IMPL_MSG_SYMBOL(GBAK, 421, gbak_plugin_schema_migration, "migrating @1 plugin objects to schema @2")
FB_IMPL_MSG_SYMBOL(GBAK, 422, gbak_plugin_schema_migration_err, "error migrating @1 plugin objects to schema @2. Plugin objects will be in inconsistent state:")
FB_IMPL_MSG_NO_SYMBOL(GBAK, 423, " @1OV(ERWRITE) allow overwriting existing backup file(s)")
FB_IMPL_MSG(GBAK, 424, gbak_backup_file_exists, -901, "00", "000", "backup file @1 already exists, use -OVERWRITE to replace")