diff options
author | unknown <sasha@mysql.sashanet.com> | 2000-09-14 16:34:50 -0600 |
---|---|---|
committer | unknown <sasha@mysql.sashanet.com> | 2000-09-14 16:34:50 -0600 |
commit | 2fdcf82ec5acae2bfd03ea00d1158ec5f9d51573 (patch) | |
tree | 6f789a128f7f2f981c423d22a6bebd80ccf71633 /sql/ha_myisam.cc | |
parent | 51fc63837a558cbf8d0ce6007012492dd71696de (diff) | |
download | mariadb-git-2fdcf82ec5acae2bfd03ea00d1158ec5f9d51573.tar.gz |
BACKUP TABLE TO 'directory'
RESTORE TABLE FROM 'directory'
log on slave when it connects to the master
include/mysql_com.h:
Added COM_CONNECT_OUT so we can log on the slave when
connects to the master
sql/ha_myisam.cc:
added restore() and backup()
sql/ha_myisam.h:
Added restore() and backup()
sql/handler.cc:
restore()/backup()
sql/handler.h:
restore()/backup()
sql/lex.h:
BACKUP/RESTORE
sql/mysql_priv.h:
gave global ( non-static) scope to generate_table()
added mysql_backup_table()/mysql_restore_table()
sql/slave.cc:
Log when slave connects to the master on the slave
sql/sql_delete.cc:
changed the scope of generate_table() from static to global
sql/sql_lex.h:
changes for BACKUP TABLE/RESTORE TABLE
sql/sql_parse.cc:
Changes for BACKUP TABLE/RESTORE TABLE
sql/sql_table.cc:
Changes for BACKUP TABLE/RESTORE TABLE
sql/sql_yacc.yy:
BACKUP TABLE/ RESTORE TABLE
Diffstat (limited to 'sql/ha_myisam.cc')
-rw-r--r-- | sql/ha_myisam.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 2c89b5303ac..9e95d2829a4 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -328,6 +328,86 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) return error ? HA_ADMIN_CORRUPT : HA_ADMIN_OK; } +int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt) +{ + HA_CHECK_OPT tmp_check_opt; + char* backup_dir = thd->lex.backup_dir; + char src_path[FN_REFLEN], dst_path[FN_REFLEN]; + int backup_dir_len = strlen(backup_dir); + char* table_name = table->real_name; + int table_name_len = strlen(table_name); + if(backup_dir_len + table_name_len + 4 >= FN_REFLEN) + return HA_ADMIN_INVALID; + memcpy(src_path, backup_dir, backup_dir_len); + char* p = src_path + backup_dir_len; + *p++ = '/'; + memcpy(p, table_name, table_name_len); + p += table_name_len; + *p = 0; + fn_format(src_path, src_path, "", MI_NAME_DEXT, 4); + + MY_STAT stat_area; + int error = 0; + char* errmsg = ""; + + + if(my_copy(src_path, fn_format(dst_path, table->path, "", + MI_NAME_DEXT, 4), MYF(MY_WME))) + { + error = HA_ADMIN_FAILED; + errmsg = "failed in my_copy( Error %d)"; + goto err; + } + + tmp_check_opt.init(); + tmp_check_opt.quick = 1; + return repair(thd, &tmp_check_opt); + + err: + { + MI_CHECK param; + myisamchk_init(¶m); + param.thd = thd; + param.op_name = (char*)"restore"; + param.table_name = table->table_name; + param.testflag = 0; + mi_check_print_error(¶m,errmsg, errno ); + return error; + } +} + +int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt) +{ + char* backup_dir = thd->lex.backup_dir; + char src_path[FN_REFLEN], dst_path[FN_REFLEN]; + int backup_dir_len = strlen(backup_dir); + char* table_name = table->real_name; + int table_name_len = strlen(table_name); + if(backup_dir_len + table_name_len + 4 >= FN_REFLEN) + return HA_ADMIN_INVALID; + memcpy(dst_path, backup_dir, backup_dir_len); + char* p = dst_path + backup_dir_len; + *p++ = '/'; + memcpy(p, table_name, table_name_len); + p += table_name_len; + *p = 0; + if(my_copy(fn_format(src_path, table->path,"", reg_ext, 4), + fn_format(dst_path, dst_path, "", reg_ext, 4), + MYF(MY_WME | MY_HOLD_ORIGINAL_MODES ))) + { + return HA_ADMIN_FAILED; + } + + *p = 0; + *(fn_ext(src_path)) = 0; + if(my_copy(fn_format(src_path, src_path,"", MI_NAME_DEXT, 4), + fn_format(dst_path, dst_path, "", MI_NAME_DEXT, 4), + MYF(MY_WME | MY_HOLD_ORIGINAL_MODES )) ) + return HA_ADMIN_FAILED; + + return HA_ADMIN_OK; +} + int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) { |