Commit 44455063 authored by sasha@mysql.sashanet.com's avatar sasha@mysql.sashanet.com
Browse files

BACKUP TABLE TO 'directory'

RESTORE TABLE FROM 'directory'
log on slave when it connects to the master
parent 243579e8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ enum enum_server_command {COM_SLEEP,COM_QUIT,COM_INIT_DB,COM_QUERY,
			  COM_PROCESS_INFO,COM_CONNECT,COM_PROCESS_KILL,
			  COM_DEBUG,COM_PING,COM_TIME,COM_DELAYED_INSERT,
			  COM_CHANGE_USER, COM_BINLOG_DUMP,
                          COM_TABLE_DUMP};
                          COM_TABLE_DUMP, COM_CONNECT_OUT};

#define NOT_NULL_FLAG	1		/* Field can't be NULL */
#define PRI_KEY_FLAG	2		/* Field is part of a primary key */
+80 −0
Original line number Diff line number Diff line
@@ -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(&param);
      param.thd = thd;
      param.op_name = (char*)"restore";
      param.table_name = table->table_name;
      param.testflag = 0;
      mi_check_print_error(&param,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)
{
+2 −0
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ class ha_myisam: public handler
  int analyze(THD* thd,HA_CHECK_OPT* check_opt);
  int repair(THD* thd, HA_CHECK_OPT* check_opt);
  int optimize(THD* thd, HA_CHECK_OPT* check_opt);
  int restore(THD* thd, HA_CHECK_OPT* check_opt);
  int backup(THD* thd, HA_CHECK_OPT* check_opt);
  int dump(THD* thd, int fd);
  int net_read_dump(NET* net);
};
+10 −0
Original line number Diff line number Diff line
@@ -337,6 +337,16 @@ int handler::check(THD* thd, HA_CHECK_OPT* check_opt)
  return HA_ADMIN_NOT_IMPLEMENTED;
}

int handler::backup(THD* thd, HA_CHECK_OPT* check_opt)
{
  return HA_ADMIN_NOT_IMPLEMENTED;
}

int handler::restore(THD* thd, HA_CHECK_OPT* check_opt)
{
  return HA_ADMIN_NOT_IMPLEMENTED;
}

int handler::repair(THD* thd, HA_CHECK_OPT* check_opt)
{
  return HA_ADMIN_NOT_IMPLEMENTED;
+3 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#define HA_ADMIN_FAILED		 -2
#define HA_ADMIN_CORRUPT         -3
#define HA_ADMIN_INTERNAL_ERROR  -4
#define HA_ADMIN_INVALID         -5

/* Bits in bas_flag to show what database can do */

@@ -248,6 +249,8 @@ class handler :public Sql_alloc
  virtual int repair(THD* thd,  HA_CHECK_OPT* check_opt);
  virtual int optimize(THD* thd,HA_CHECK_OPT* check_opt);
  virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt);
  virtual int backup(THD* thd, HA_CHECK_OPT* check_opt);
  virtual int restore(THD* thd, HA_CHECK_OPT* check_opt);
  virtual int dump(THD* thd, int fd = -1) { return ER_DUMP_NOT_IMPLEMENTED; }
  virtual void deactivate_non_unique_index(ha_rows rows) {}
  virtual bool activate_all_index(THD *thd) {return 0;}
Loading