--- mysqldump.c.prev Tue Jan 29 23:41:30 2008 +++ mysqldump.c Wed Mar 5 11:39:59 2008 @@ -123,7 +123,12 @@ static int first_error=0; static DYNAMIC_STRING extended_row; #include FILE *md_result_file= 0; +FILE *md_result_file_orig; FILE *stderror_file=0; +static char master_file[256]=""; +static char master_pos[256]=""; +static char gzdir[256]=""; +static char gzdircmd[256]=""; #ifdef HAVE_SMEM static char *shared_memory_base_name=0; @@ -396,6 +401,9 @@ static struct my_option my_long_options[ {"result-file", 'r', "Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed).", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"result-gzdir", 'g', + "Direct gzipped output to a given directory.", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"routines", 'R', "Dump stored routines (functions and procedures).", (uchar**) &opt_routines, (uchar**) &opt_routines, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -484,6 +492,7 @@ static int dump_all_databases(); static char *quote_name(const char *name, char *buff, my_bool force); char check_if_ignore_table(const char *table_name, char *table_type); static char *primary_key_fields(const char *table_name); +static int do_show_master_status(MYSQL *mysql_con); static my_bool get_view_structure(char *table, char* db); static my_bool dump_all_views_in_db(char *database); static int dump_all_tablespaces(); @@ -718,6 +727,9 @@ get_one_option(int optid, const struct m MYF(MY_WME)))) exit(1); break; + case 'g': + strncpy(gzdir,argument,255); + break; case 'W': #ifdef __WIN__ opt_protocol= MYSQL_PROTOCOL_PIPE; @@ -3994,6 +4006,13 @@ static int dump_all_tables_in_db(char *d char *end= strmov(afterdot, table); if (include_table((uchar*) hash_key, end - hash_key)) { + if (gzdir[0]) { + md_result_file_orig=md_result_file; + snprintf(gzdircmd,255,"/usr/bin/gzip >%s/%s.sql.gz",gzdir,table); + md_result_file=popen(gzdircmd,"w"); + write_header(md_result_file, NULL); + if (opt_master_data && do_show_master_status(mysql)) {}; + } dump_table(table,database); my_free(order_by, MYF(MY_ALLOW_ZERO_PTR)); order_by= 0; @@ -4007,6 +4026,11 @@ static int dump_all_tables_in_db(char *d maybe_exit(EX_MYSQLERR); } } + if (gzdir[0]) { + write_footer(md_result_file); + pclose(md_result_file); + md_result_file=md_result_file_orig; + } } } if (opt_events && !opt_xml && @@ -4229,6 +4253,13 @@ static int dump_selected_tables(char *db for (pos= dump_tables; pos < end; pos++) { DBUG_PRINT("info",("Dumping table %s", *pos)); + if (gzdir[0]) { + md_result_file_orig=md_result_file; + snprintf(gzdircmd,255,"/usr/bin/gzip >%s/%s.gz",gzdir,*pos); + md_result_file=popen(gzdircmd,"w"); + write_header(md_result_file, NULL); + if (opt_master_data && do_show_master_status(mysql)) {}; + } dump_table(*pos, db); if (opt_dump_triggers && mysql_get_server_version(mysql) >= 50009) @@ -4240,6 +4271,11 @@ static int dump_selected_tables(char *db maybe_exit(EX_MYSQLERR); } } + if (gzdir[0]) { + write_footer(md_result_file); + pclose(md_result_file); + md_result_file=md_result_file_orig; + } } /* Dump each selected view */ @@ -4281,6 +4317,7 @@ static int do_show_master_status(MYSQL * MYSQL_RES *master; const char *comment_prefix= (opt_master_data == MYSQL_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : ""; + if (!(master_file[0])) { if (mysql_query_with_error_report(mysql_con, &master, "SHOW MASTER STATUS")) { return 1; @@ -4290,15 +4327,8 @@ static int do_show_master_status(MYSQL * row= mysql_fetch_row(master); if (row && row[0] && row[1]) { - /* SHOW MASTER STATUS reports file and position */ - if (opt_comments) - fprintf(md_result_file, - "\n--\n-- Position to start replication or point-in-time " - "recovery from\n--\n\n"); - fprintf(md_result_file, - "%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", - comment_prefix, row[0], row[1]); - check_io(md_result_file); + strncpy(master_file,row[0],255); + strncpy(master_pos,row[1],255); } else if (!ignore_errors) { @@ -4309,6 +4339,18 @@ static int do_show_master_status(MYSQL * return 1; } mysql_free_result(master); + } + } + if (master_file[0]) { + /* SHOW MASTER STATUS reports file and position */ + if (opt_comments) + fprintf(md_result_file, + "\n--\n-- Position to start replication or point-in-time " + "recovery from\n--\n\n"); + fprintf(md_result_file, + "%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", + comment_prefix, master_file, master_pos); + check_io(md_result_file); } return 0; }