Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ TARGET_LINK_LIBRARIES(mariadb-conv mysys strings)

IF(WIN32)
MYSQL_ADD_EXECUTABLE(echo echo.c COMPONENT Test)
ENDIF(WIN32)
ELSE()
# just a code example, do not install it
CONFIGURE_FILE(mariadb-backup-cat mariadb-backup-cat COPYONLY)
ENDIF()

# async_example is just a code example, do not install it.
ADD_EXECUTABLE(async_example async_example.c)
Expand Down
3 changes: 3 additions & 0 deletions client/mariadb-backup-cat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
exec cat > "$MARIADB_DATADIR/$1.tar"
Comment thread
dr-m marked this conversation as resolved.
Resolved
# This is for use by mysql-test/mtr backup.backup_stream
26 changes: 22 additions & 4 deletions extra/mariabackup/aria_backup_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ bool Table::copy(ds_ctxt_t *ds, bool is_index, unsigned thread_num) {
for (const Partition &partition : m_partitions) {
ds_file_t *dst_file = nullptr;
uchar *copy_buffer = nullptr;
size_t copy_length;
std::string full_name = partition.m_file_path + ext;
const char *dst_path =
(xtrabackup_copy_back || xtrabackup_move_back) ?
Expand All @@ -392,9 +393,10 @@ bool Table::copy(ds_ctxt_t *ds, bool is_index, unsigned thread_num) {
goto err;
}

copy_length= m_cap.block_size * 128;
copy_buffer =
reinterpret_cast<uchar *>(my_malloc(PSI_NOT_INSTRUMENTED,
m_cap.block_size, MYF(0)));
copy_length, MYF(0)));

DBUG_MARIABACKUP_EVENT_LOCK(
is_index ?
Expand All @@ -403,14 +405,22 @@ bool Table::copy(ds_ctxt_t *ds, bool is_index, unsigned thread_num) {
fil_space_t::name_type(m_sql_name.data(),
m_sql_name.size()));

for (ulonglong block= 0 ; ; block++) {
/*
aria_read_index() and aria_read_data() are used instead
of aria_read_index_file() and aria_read_data_file() as
we also have to copy tables that are not transactional
and not block based.
*/
for (ulonglong block= 0 ; ;) {
size_t length = m_cap.block_size;
if (is_index)
error= aria_read_index(partition.m_index_file, &m_cap,
block, copy_buffer);
block, copy_buffer,
copy_length, &length);
else
error= aria_read_data(partition.m_data_file, &m_cap,
block, copy_buffer, &length);
block, copy_buffer, copy_length,
&length);
if (error)
{
if (error == HA_ERR_END_OF_FILE)
Expand All @@ -427,6 +437,14 @@ bool Table::copy(ds_ctxt_t *ds, bool is_index, unsigned thread_num) {
"with error: %d", dst_path, error);
goto err;
}
/*
A table without checksums is not block based,
which means that the last read can end in the
middle of a block. Round up to get the next
read after the data we just copied.
*/
block+= ((length + m_cap.block_size - 1) /
m_cap.block_size);
}

DBUG_MARIABACKUP_EVENT_LOCK(
Expand Down
4 changes: 2 additions & 2 deletions include/aligned.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# include <malloc.h>
#endif

inline void *aligned_malloc(size_t size, size_t alignment)
static inline void *aligned_malloc(size_t size, size_t alignment)
{
#ifdef _WIN32
return _aligned_malloc(size, alignment);
Expand All @@ -32,7 +32,7 @@ inline void *aligned_malloc(size_t size, size_t alignment)
#endif
}

inline void aligned_free(void *ptr)
static inline void aligned_free(void *ptr)
{
IF_WIN(_aligned_free,free)(ptr);
}
84 changes: 78 additions & 6 deletions include/aria_backup.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2018,2020 MariaDB Corporation Ab
/* Copyright (C) 2018,2026 MariaDB plc

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -15,14 +15,21 @@

/* Interfaces for doing backups of Aria tables */

#ifndef ARIA_BACKUP_INCLUDED
#pragma once

C_MODE_START

typedef struct st_aria_table_capabilities
{
my_off_t header_size;
MARIA_CRYPT_DATA *crypt_data;
/*
Buffer used when decrypting a page to check its checksum.
Allocated by aria_get_capabilities() for encrypted tables.
A capabilities object must not be used by two threads at the same
time, as they would share this buffer.
*/
uchar *crypt_buffer;
uint crypt_page_header_space;
ulong bitmap_pages_covered;
uint block_size;
Expand All @@ -42,9 +49,74 @@ typedef struct st_aria_table_capabilities
int aria_get_capabilities(File kfile, const char *table_name, ARIA_TABLE_CAPABILITIES *cap);
void aria_free_capabilities(ARIA_TABLE_CAPABILITIES *cap);
int aria_read_index(File kfile, ARIA_TABLE_CAPABILITIES *cap, ulonglong block,
uchar *buffer);
uchar *buffer, size_t buffer_size, size_t *bytes_read);
int aria_read_data(File dfile, ARIA_TABLE_CAPABILITIES *cap, ulonglong block,
uchar *buffer, size_t *bytes_read);
C_MODE_END
uchar *buffer, size_t buffer_size, size_t *bytes_read);

/*
Simple interface for copying an Aria table.

The context stores the files and the position in them, which means
that the caller only has to call aria_read_index_file() and
aria_read_data_file() until they return 0 (end of file).

Copying of an Aria table starts with aria_open_files_for_backup()
and ends with aria_close_files_for_backup().
*/

typedef struct st_aria_backup_context
{
File kfile, dfile;
ulonglong kblock; /* Position in key file */
ulonglong dblock; /* Position in data file */
ARIA_TABLE_CAPABILITIES capabilities;
/* Real path of the index file, to find the open table */
char index_name[FN_REFLEN];
} ARIA_BACKUP_CONTEXT;

/**
Open the index and data file of an Aria table and initialize the
context. A symbolic link that maria_open() would refuse is refused.

@param path table file name without extension
@return error number; errors will have been reported
@retval 0 success
*/

int aria_open_files_for_backup(const char *path,
ARIA_BACKUP_CONTEXT *context);
/* Close the files after a successful aria_open_files_for_backup() */
void aria_close_files_for_backup(ARIA_BACKUP_CONTEXT *context);

#endif /* ARIA_BACKUP_INCLUDED */
/**
@brief Read the next part of the index file

@param context Backup context with the open files and the
position in them
@param buffer read data to this buffer
@param buff_length Size of buffer. Must be a multiple of block_size

@return number of bytes read, or negated error code
@retval 0 End of file
*/

longlong aria_read_index_file(ARIA_BACKUP_CONTEXT *context,
uchar *buffer, size_t buff_length);

/**
Read a set of pages from a TRANSACTIONAL=1 data file (using checksums)
that may be written to concurrently.

@param context Backup context with the open files and the
position in them
@param buffer read data to this buffer
@param buff_length Size of buffer. Must be a multiple of block_size

@return number of bytes read, or negated error code
@retval 0 End of file
*/

longlong aria_read_data_file(ARIA_BACKUP_CONTEXT *context,
uchar *buffer, size_t buff_length);

C_MODE_END
33 changes: 33 additions & 0 deletions include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,12 +674,39 @@ int my_b_pread(IO_CACHE *info, uchar *Buffer, size_t Count, my_off_t pos);

typedef uint32 ha_checksum;

/*
The native file handle of the operating system, for the few places
that have to give a file opened by my_open() or my_create() to a
function that is not part of mysys.
*/

typedef IF_WIN(HANDLE, File) my_native_file;

extern int (*mysys_test_invalid_symlink)(const char *filename);
#include <my_alloc.h>
#ifdef __APPLE__
# include <copyfile.h>
#endif

/* Prototypes for mysys and my_func functions */

extern int my_copy(const char *from,const char *to,myf MyFlags);
#ifdef _WIN32
/* you should use my_copy() instead of my_copy_file() */
#elif defined __APPLE__
# define my_copy_file(from, to) \
fcopyfile(from, to, NULL, COPYFILE_ALL | COPYFILE_CLONE)
#else
extern int my_copy_file(my_native_file from, my_native_file to);
#endif
#ifndef __linux__
# define my_clone_file_range(from, to, start, length) 1
#else
extern int my_clone_file_range(my_native_file from, my_native_file to,
uint64_t start, uint64_t length);
#endif
extern int my_copy_file_range(my_native_file from, my_native_file to,
my_off_t start, my_off_t end);
extern int my_delete(const char *name,myf MyFlags);
extern int my_rmtree(const char *name, myf Myflags);
extern int my_getwd(char * buf,size_t size,myf MyFlags);
Expand Down Expand Up @@ -758,6 +785,12 @@ extern File my_win_handle2File(HANDLE hFile);
extern void my_osmaperr(unsigned long last_error);
#endif

#ifdef _WIN32
#define my_native_file_handle(fd) my_get_osfhandle(fd)
#else
#define my_native_file_handle(fd) (fd)
#endif

extern void init_glob_errs(void);
extern const char** get_global_errmsgs(int nr);
extern void wait_for_free_space(const char *filename, int errors);
Expand Down
1 change: 1 addition & 0 deletions libmysqld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/opt_context_store_replay.cc ../sql/opt_context_store_replay.h
../sql/sql_path.cc
../sql/sql_json_lib.cc ../sql/sql_json_lib.h
../sql/sql_backup.cc
${GEN_SOURCES}
${MYSYS_LIBWRAP_SOURCE}
)
Expand Down
1 change: 1 addition & 0 deletions mysql-test/collections/buildbot_suites.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ binlog_in_engine,^
versioning,^
plugins,^
mariabackup,^
backup,^
roles,^
auth_gssapi,^
mysql_sha2,^
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/backup_priv.result
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Test privileges for BACKUP STAGES
#
set sql_mode="";
GRANT RELOAD ON *.* TO user1@localhost;
GRANT RELOAD, SELECT ON *.* TO user1@localhost;
GRANT CREATE, DROP ON *.* TO user2@localhost;
connect con1, localhost, user1;
BACKUP STAGE START;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/backup_priv.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

set sql_mode="";

GRANT RELOAD ON *.* TO user1@localhost;
GRANT RELOAD, SELECT ON *.* TO user1@localhost;
GRANT CREATE, DROP ON *.* TO user2@localhost;

--connect(con1, localhost, user1)
Expand Down
6 changes: 6 additions & 0 deletions mysql-test/main/backup_server.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BACKUP SERVER TO '$datadir/some_directory';
ERROR HY000: Incorrect arguments to BACKUP SERVER TO
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
ERROR HY000: Can't create directory 'MYSQLTEST_VARDIR/some_directory' (Errcode: 17 "File exists")
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
12 changes: 12 additions & 0 deletions mysql-test/main/backup_server.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--let $datadir=`select @@datadir`
--error ER_WRONG_ARGUMENTS
evalp BACKUP SERVER TO '$datadir/some_directory';
--error 0,1
--rmdir $MYSQLTEST_VARDIR/some_directory
evalp BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--error 21
evalp BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
--rmdir $MYSQLTEST_VARDIR/some_directory
evalp BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
--rmdir $MYSQLTEST_VARDIR/some_directory
17 changes: 17 additions & 0 deletions mysql-test/main/backup_server_locking.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
ERROR HY000: Can't create directory 'MYSQLTEST_VARDIR/some_directory' (Errcode: 17 "File exists")
BACKUP STAGE START;
connect backup,localhost,root;
SET STATEMENT max_statement_time=0.1 FOR
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
ERROR 70100: Query was interrupted: execution time limit 0.1 sec exceeded
connection default;
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
ERROR HY000: Backup stage 'START' is same or before current backup stage 'START'
BACKUP STAGE END;
connection backup;
SET STATEMENT max_statement_time=0.1 FOR
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
ERROR HY000: Can't create directory 'MYSQLTEST_VARDIR/some_directory' (Errcode: 17 "File exists")
disconnect backup;
connection default;
31 changes: 31 additions & 0 deletions mysql-test/main/backup_server_locking.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--source include/not_embedded.inc
--source include/count_sessions.inc

--mkdir $MYSQLTEST_VARDIR/some_directory
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--error 21
evalp BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';

BACKUP STAGE START;
--connect (backup,localhost,root)
--error ER_STATEMENT_TIMEOUT
evalp SET STATEMENT max_statement_time=0.1 FOR
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';

--connection default

--error ER_BACKUP_WRONG_STAGE
evalp BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';

BACKUP STAGE END;
--connection backup
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--error 21
evalp SET STATEMENT max_statement_time=0.1 FOR
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
--disconnect backup
--connection default

--rmdir $MYSQLTEST_VARDIR/some_directory

--source include/wait_until_count_sessions.inc
27 changes: 27 additions & 0 deletions mysql-test/main/grant_backup_server.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE USER user1@localhost IDENTIFIED BY '';
connect con1,localhost,user1;
BACKUP SERVER TO 'some_directory';
ERROR HY000: Incorrect arguments to BACKUP SERVER TO
disconnect con1;
connection default;
GRANT SELECT ON test.* TO user1@localhost;
connect con1,localhost,user1;
BACKUP SERVER TO 'some_directory';
ERROR HY000: Incorrect arguments to BACKUP SERVER TO
disconnect con1;
connection default;
GRANT RELOAD ON test.* TO user1@localhost;
ERROR HY000: Incorrect usage of DB GRANT and GLOBAL PRIVILEGES
GRANT RELOAD ON *.* TO user1@localhost;
connect con1,localhost,user1;
BACKUP SERVER TO 'some_directory';
ERROR HY000: Incorrect arguments to BACKUP SERVER TO
disconnect con1;
connection default;
GRANT SELECT ON *.* TO user1@localhost;
connect con1,localhost,user1;
BACKUP SERVER TO '$datadir/some_directory';
ERROR HY000: Incorrect arguments to BACKUP SERVER TO
disconnect con1;
connection default;
DROP USER user1@localhost;
Loading
Loading