19
18
#define DATA_BUFFER_SIZE (1024*1024)
21
Functions used to initialize and shut down the online backup system.
23
Note: these functions are called at plugin load and plugin shutdown time,
27
void backup_shutdown();
22
30
Called from the big switch in mysql_execute_command() to execute
23
31
backup related statement
25
33
int execute_backup_command(THD*, LEX*);
35
// forward declarations
31
38
class Restore_info;
37
int mysql_backup(THD*, backup::Backup_info&, backup::OStream&);
38
int mysql_restore(THD*, backup::Restore_info&, backup::IStream&);
46
class Native_snapshot;
48
int write_table_data(THD*, Backup_info&, Output_stream&);
49
int restore_table_data(THD*, Restore_info&, Input_stream&);
44
Represents a location where backup archive can be stored.
46
The class is supposed to represent the location on the abstract level
47
so that it is easier to add new types of locations.
49
Currently we support only files on the server's file system. Thus the
50
only type of location is a path to a file.
54
Instances of this class are used for creating required context and performing
55
backup/restore operations.
59
class Backup_restore_ctx: public backup::Logger
56
enum enum_type {SERVER_FILE, INVALID};
59
virtual enum_type type() const
62
virtual ~Location() {} // we want to inherit this class
64
/// Deallocate any resources used by Location object.
66
{ delete this; } // use destructor to free resources
63
Backup_restore_ctx(THD*);
64
~Backup_restore_ctx();
66
bool is_valid() const;
67
ulonglong op_id() const;
69
Backup_info* prepare_for_backup(LEX_STRING location, const char*, bool);
70
Restore_info* prepare_for_restore(LEX_STRING location, const char*);
74
int fatal_error(int, ...);
78
THD* thd() const { return m_thd; }
82
/** Indicates if a backup/restore operation is in progress. */
83
static bool is_running;
84
static pthread_mutex_t run_lock; ///< To guard @c is_running flag.
69
Determine if the location is valid
71
An invalid location will not be used.
87
@brief State of a context object.
73
@retval TRUE Location is valid.
74
@retval FALSE Location is invalid.
76
virtual bool is_valid() =0;
78
/// Describe location for debug purposes
79
virtual const char* describe()
80
{ return "Invalid location"; }
89
Backup/restore can be performed only if object is prepared for that operation.
96
ulonglong m_thd_options; ///< For saving thd->options.
83
Remove any system resources connected to that location.
85
When location is opened for writing, some system resources will be usually
86
created (depending on the type of the location). For example, a file in the
87
file system. This method should remove/free any such resources. If no
88
resources were created, the method should do nothing.
90
@returns OK on success, ERROR otherwise.
98
If backup/restore was interrupted by an error, this member stores the error
92
virtual result_t remove() =0;
95
Interpret string passed to BACKUP/RESTORE statement as backup location
96
and construct corresponding Location object.
98
@returns NULL if the string doesn't denote a valid location
100
static Location* find(const LEX_STRING&);
103
const char *m_path; ///< Path to where the backup image file is located.
105
/** If true, the backup image file is deleted at clean-up time. */
108
backup::Stream *m_stream; ///< Pointer to the backup stream object, if opened.
109
backup::Image_info *m_catalog; ///< Pointer to the image catalogue object.
111
/** Memory allocator for backup stream library. */
112
static backup::Mem_allocator *mem_alloc;
114
int prepare(LEX_STRING location);
115
void disable_fkey_constraints();
116
int restore_triggers_and_events();
119
Indicates if tables have been locked with @c lock_tables_for_restore()
121
bool m_tables_locked;
123
int lock_tables_for_restore();
126
friend class Backup_info;
127
friend class Restore_info;
128
friend int backup_init();
129
friend void backup_shutdown();
130
friend bstream_byte* bstream_alloc(unsigned long int);
131
friend void bstream_free(bstream_byte *ptr);
134
/// Check if instance is correctly created.
136
bool Backup_restore_ctx::is_valid() const
141
/// Return global id of the backup/restore operation.
143
ulonglong Backup_restore_ctx::op_id() const
145
return m_op_id; // inherited from Logger class
148
/// Disable foreign key constraint checks (needed during restore).
150
void Backup_restore_ctx::disable_fkey_constraints()
152
m_thd->options|= OPTION_NO_FOREIGN_KEY_CHECKS;
105
Specialization of @c Image_info which adds methods for selecting items
108
When Backup_info object is created it is empty and ready for adding items
109
to it. Methods @c add_table() @c add_db(), @c add_dbs() and @c add_all_dbs()
110
can be used for that purpose (currently only databases and tables are
111
supported). After populating info object with items it should be "closed"
112
with a call to @c close() method. After that it is ready for use as a
113
description of backup archive to be created.
156
Report error and move context object into error state.
158
After this method is called the context object is in error state and
159
cannot be normally used. It still can be examined for saved error messages.
160
The code of the error reported here is saved in m_error member.
162
Only one fatal error can be reported. If context is already in error
163
state when this method is called, it does nothing.
165
@return error code given as input or stored in the context object if
166
a fatal error was reported before.
169
int Backup_restore_ctx::fatal_error(int error_code, ...)
179
va_start(args,error_code);
180
v_report_error(backup::log_level::ERROR, error_code, args);
187
Now, when Backup_restore_ctx is defined, include definitions
188
of Backup_info and Restore_info classes.
115
class Backup_info: public Image_info, public Logger
133
ok= (i_s_tables != NULL);
146
int add_dbs(List< ::LEX_STRING >&);
153
/// State of the info structure.
154
enum {INIT, // structure ready for filling
155
READY, // structure ready for backup (tables opened)
156
DONE, // tables are closed
160
int find_backup_engine(const ::TABLE *const, const Table_ref&);
162
Table_item* add_table(Db_item&, const Table_ref&);
164
int add_db_items(Db_item&);
165
int add_table_items(Table_item&);
169
String binlog_file_name; ///< stores name of the binlog at VP time
172
@brief Storage for table and database names.
174
When adding tables or databases to the backup catalogue, their names
175
are stored in String objects, and these objects are appended to this
176
list so that they can be freed when Backup_info object is destroyed.
178
// FIXME: use better solution, e.g., MEM_ROOT
179
List<String> name_strings;
181
void save_binlog_pos(const ::LOG_INFO &li)
183
binlog_file_name= li.log_file_name;
184
binlog_file_name.copy();
185
binlog_pos.pos= (unsigned long int)li.pos;
186
binlog_pos.file= binlog_file_name.c_ptr();
189
friend int write_table_data(THD*, Backup_info&, OStream&);
194
Specialization of @c Image_info which is used to select and restore items
197
An instance of this class is created by reading backup image header and it
198
describes its contents. @c Restore_info methods select which items
201
@note This class is not fully implemented. Right now it is not possible to
202
select items to restore - always all items are restored.
205
class Restore_info: public Image_info, public Logger
209
const Db_ref *curr_db;
211
CHARSET_INFO *system_charset;
212
bool same_sys_charset;
216
Restore_info(THD*, IStream&);
219
bool is_valid() const
222
int restore_all_dbs()
225
/// Determine if given item is selected for restore.
226
bool selected(const Image_info::Item&)
229
result_t restore_item(Item &it, String &sdata, String&);
231
friend int restore_table_data(THD*, Restore_info&, IStream&);
232
friend int ::bcat_add_item(st_bstream_image_header*,
233
struct st_bstream_item_info*);
236
} // backup namespace
191
#include <backup/backup_info.h>
192
#include <backup/restore_info.h>