Skip to content
Draft
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
41 changes: 41 additions & 0 deletions mysql-test/main/backup_server_restore.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Prepare database
CREATE TABLE tinno (i INTEGER) ENGINE=InnoDB;
INSERT INTO tinno VALUES (1), (2), (3), (4);
CREATE TABLE tariatr (i INTEGER) ENGINE=Aria TRANSACTIONAL=1;
INSERT INTO tariatr VALUES (2), (3), (5), (7);
CREATE TABLE tariant (i INTEGER) ENGINE=Aria TRANSACTIONAL=0;
INSERT INTO tariant VALUES (1), (1), (2), (3), (5);
Back up the database
BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';
Restore the database
# restart: --datadir=MYSQLTEST_VARDIR/some_directory
Check contents after restore
SELECT * FROM tinno;
i
1
2
3
4
SELECT * FROM tariatr;
i
2
3
5
7
SELECT * FROM tariant;
i
1
1
2
3
5
Warnings:
Error 145 Got error '145 "Table was marked as crashed and should be repaired"' for './test/tariant'
Warning 1034 1 client is using or hasn't closed the table properly
Note 1034 Table is fixed
Restart database in original data directory
# restart
Clean up
DROP TABLE tinno;
DROP TABLE tariatr;
DROP TABLE tariant;
38 changes: 38 additions & 0 deletions mysql-test/main/backup_server_restore.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--source include/not_windows.inc
--source include/have_innodb.inc

--echo Prepare database
CREATE TABLE tinno (i INTEGER) ENGINE=InnoDB;
INSERT INTO tinno VALUES (1), (2), (3), (4);
CREATE TABLE tariatr (i INTEGER) ENGINE=Aria TRANSACTIONAL=1;
INSERT INTO tariatr VALUES (2), (3), (5), (7);
CREATE TABLE tariant (i INTEGER) ENGINE=Aria TRANSACTIONAL=0;
INSERT INTO tariant VALUES (1), (1), (2), (3), (5);

--echo Back up the database
evalp BACKUP SERVER TO '$MYSQLTEST_VARDIR/some_directory';

--echo Restore the database
--disable_query_log
call mtr.add_suppression("InnoDB: Did not find any checkpoint after LSN=");
call mtr.add_suppression("InnoDB: Renaming ib_[0-9]+.log to ib_logfile0");
call mtr.add_suppression("mariadbd: Got error '145 \"Table was marked as crashed and should be repaired\"' for ");
call mtr.add_suppression("Checking table: ");
--enable_query_log
--let $restart_parameters=--datadir=$MYSQLTEST_VARDIR/some_directory
--source include/restart_mysqld.inc

--echo Check contents after restore
SELECT * FROM tinno;
SELECT * FROM tariatr;
SELECT * FROM tariant;

--echo Restart database in original data directory
--let $restart_parameters=
--source include/restart_mysqld.inc

--echo Clean up
DROP TABLE tinno;
DROP TABLE tariatr;
DROP TABLE tariant;
--rmdir $MYSQLTEST_VARDIR/some_directory
4 changes: 1 addition & 3 deletions sql/sql_backup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
#include "sql_backup_interface.h"
#include "sql_parse.h"

#ifdef _WIN32
#elif defined __APPLE__
#else
#if !defined __APPLE__ && !defined _WIN32
using copying_step= ssize_t(int,int,size_t,off_t*);
template<copying_step step>
static ssize_t copy(int in_fd, int out_fd, off_t c) noexcept
Expand Down
42 changes: 29 additions & 13 deletions sql/sql_backup_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,34 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */

#ifdef _WIN32
/* You have to use CopyFileEx() and friends manually */
#elif defined __APPLE__
#ifdef __APPLE__
# include <sys/attr.h>
# include <sys/clonefile.h>
# include <copyfile.h>
# define copy_file(src, dst, off) \
fcopyfile(src, dst, nullptr, COPYFILE_ALL | COPYFILE_CLONE)
# define copy_entire_file(src, dst) copy_file(src, dst,)
#else
# ifdef __cplusplus
#endif

#ifdef __cplusplus
extern "C"
# endif
{
#endif

#ifdef _WIN32
/* You have to use CopyFileEx() and friends manually */
#elif defined __APPLE__

inline
int copy_entire_file(int src, int dst)
{
return fcopyfile(src, dst, nullptr, COPYFILE_ALL | COPYFILE_CLONE);
}

inline
int copy_file(int src, int dst, off_t)
{
return fcopyfile(src, dst, nullptr, COPYFILE_ALL | COPYFILE_CLONE);
}

#else
/** Copy a file.
@param src source file descriptor
@param dst target to append src to
Expand All @@ -34,14 +49,15 @@ extern "C"
@retval 0 on success */
int copy_file(int src, int dst, off_t size);

# ifdef __cplusplus
extern "C"
# endif

/** Copy an entire file.
@param src source file descriptor
@param dst target to append src to
@param size amount of data to be copied
@return error code (negative)
@retval 0 on success */
int copy_entire_file(int src, int dst);
#endif

#ifdef __cplusplus
}
#endif
6 changes: 6 additions & 0 deletions storage/innobase/handler/backup_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#include "trx0trx.h"
#include <vector>

#ifdef __APPLE__
# include <sys/attr.h>
# include <sys/clonefile.h>
# include <copyfile.h>
#endif

/** Associate a transaction with the current session
@param thd session
@return InnoDB transaction */
Expand Down
1 change: 1 addition & 0 deletions storage/maria/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ SET(ARIA_SOURCES ma_init.c ma_open.c ma_extra.c ma_info.c ma_rkey.c
ha_maria.h maria_def.h ma_recovery_util.c ma_servicethread.c
ma_norec.c
ma_crypt.c ma_backup.c
ma_backup.cc ma_backup.h
)

IF(APPLE)
Expand Down
4 changes: 4 additions & 0 deletions storage/maria/ha_maria.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <myisampack.h>
#include <my_bit.h>
#include "ha_maria.h"
#include "ma_backup.h"
#include "trnman_public.h"
#include "trnman.h"

Expand Down Expand Up @@ -3941,6 +3942,9 @@ static int ha_maria_init(void *p)
maria_hton->prepare_for_backup= maria_prepare_for_backup;
maria_hton->end_backup= maria_end_backup;
maria_hton->update_optimizer_costs= aria_update_optimizer_costs;
maria_hton->backup_start= aria_backup_start;
maria_hton->backup_step= aria_backup_step;
maria_hton->backup_end= aria_backup_end;

/* TODO: decide if we support Maria being used for log tables */
maria_hton->flags= (HTON_CAN_RECREATE | HTON_SUPPORT_LOG_TABLES |
Expand Down
Loading
Loading