#At file:///home/thava/repo/backup/ based on revid:rafal.somla@stripped
2880 Thava Alagu 2009-10-21
BUG#36402 - Backup needs option to overwrite backup image
The backup sql command now takes additional option "OVERWRITE"
to overwrite backup image file even if one exists with the same name.
modified:
mysql-test/suite/backup/r/backup_errors.result
mysql-test/suite/backup/t/backup_errors.test
sql/backup/backup_kernel.h
sql/backup/kernel.cc
sql/backup/stream.cc
sql/backup/stream.h
sql/sql_parse.cc
sql/sql_yacc.yy
=== modified file 'mysql-test/suite/backup/r/backup_errors.result'
--- a/mysql-test/suite/backup/r/backup_errors.result 2009-10-12 09:08:34 +0000
+++ b/mysql-test/suite/backup/r/backup_errors.result 2009-10-21 12:15:53 +0000
@@ -75,16 +75,27 @@ Level Code Message
Error # Can't create/write to file 'MYSQLD_DATADIR/test.bak' (Errcode: #)
Error # Can't write to backup location 'test.bak'
Warning # Operation aborted
+# overwrite existing backup image if overwrite option specified
+BACKUP DATABASE adb TO "test.bak" OVERWRITE;
+backup_id
+#
+SHOW WARNINGS;
+Level Code Message
verify backup history and progress logs for backup_state.
SELECT backup_state,operation, backup_file, command FROM mysql.backup_history;
backup_state operation backup_file command
error backup test.bak BACKUP DATABASE adb TO "test.bak"
+complete backup test.bak BACKUP DATABASE adb TO "test.bak" OVERWRITE
SELECT notes FROM mysql.backup_progress;
notes
starting
running
Can't write to backup location 'test.bak'
error
+starting
+running
+vp time
+complete
# non-existent database
DROP DATABASE IF EXISTS foo;
DROP DATABASE IF EXISTS bar;
=== modified file 'mysql-test/suite/backup/t/backup_errors.test'
--- a/mysql-test/suite/backup/t/backup_errors.test 2009-03-10 10:02:06 +0000
+++ b/mysql-test/suite/backup/t/backup_errors.test 2009-10-21 12:15:53 +0000
@@ -90,6 +90,12 @@ eval BACKUP DATABASE adb TO "test.bak" $
--replace_regex /Errcode: [0-9]+/Errcode: #/
SHOW WARNINGS;
+--echo # overwrite existing backup image if overwrite option specified
+--replace_column 1 #
+eval BACKUP DATABASE adb TO "test.bak" $compression OVERWRITE;
+# Overwriting backup image should succeed now.
+SHOW WARNINGS;
+
--echo verify backup history and progress logs for backup_state.
SELECT backup_state,operation, backup_file, command FROM mysql.backup_history;
SELECT notes FROM mysql.backup_progress;
=== modified file 'sql/backup/backup_kernel.h'
--- a/sql/backup/backup_kernel.h 2009-10-12 09:08:34 +0000
+++ b/sql/backup/backup_kernel.h 2009-10-21 12:15:53 +0000
@@ -75,7 +75,7 @@ public:
Backup_info* prepare_for_backup(String *location,
LEX_STRING orig_loc,
- const char*, bool);
+ const char*, bool, bool);
Restore_info* prepare_for_restore(String *location,
LEX_STRING orig_loc,
const char*, bool);
=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc 2009-10-12 09:08:34 +0000
+++ b/sql/backup/kernel.cc 2009-10-21 12:15:53 +0000
@@ -163,8 +163,8 @@ static int send_reply(Backup_restore_ctx
@param[in] thd current thread object reference.
@param[in] lex results of parsing the statement.
@param[in] backupdir value of the backupdir variable from server.
- @param[in] overwrite whether or not restore should overwrite existing
- DB with same name as in backup image
+ @param[in] overwrite For restore: should overwrite DB with same name.
+ For backup: should overwrite backup image file.
@param[in] skip_gap_event whether or not restore should skip writing
the gap event if run on a master in an active
replication scenario
@@ -213,7 +213,8 @@ execute_backup_command(THD *thd,
DEBUG_SYNC(thd, "before_backup_prepare");
Backup_info *info= context.prepare_for_backup(backupdir, lex->backup_dir,
thd->query,
- lex->backup_compression);
+ lex->backup_compression,
+ overwrite);
// reports errors
// Error condition insertion for ER_BACKUP_BACKUP_PREPARE.
@@ -730,7 +731,8 @@ Backup_info*
Backup_restore_ctx::prepare_for_backup(String *backupdir,
LEX_STRING orig_loc,
const char *query,
- bool with_compression)
+ bool with_compression,
+ bool overwrite)
{
using namespace backup;
@@ -771,7 +773,8 @@ Backup_restore_ctx::prepare_for_backup(S
DEBUG_SYNC(m_thd, "before_backup_open_stream");
Output_stream *s= new Output_stream(*this,
&m_path,
- with_compression);
+ with_compression,
+ overwrite);
m_stream= s;
if (!s || is_killed())
=== modified file 'sql/backup/stream.cc'
--- a/sql/backup/stream.cc 2009-10-12 09:08:34 +0000
+++ b/sql/backup/stream.cc 2009-10-21 12:15:53 +0000
@@ -425,10 +425,11 @@ int Stream::close()
Output_stream::Output_stream(Logger &log, ::String *path,
- bool with_compression)
+ bool with_compression, bool overwrite)
:Stream(log, path, 0)
{
m_with_compression= with_compression;
+ m_overwrite= overwrite;
stream.write= stream_write;
m_block_size=0; // use default block size provided by the backup stram library
}
@@ -517,12 +518,15 @@ int Output_stream::open()
MY_STAT stat_info;
close(); // If close() should fail, we will still try to open
- /* Allow to write to existing named pipe */
- if (my_stat(m_path->c_ptr(), &stat_info, MYF(0)) &&
- MY_S_ISFIFO(stat_info.st_mode))
- m_flags= O_WRONLY;
- else
- m_flags= O_WRONLY|O_CREAT|O_EXCL|O_TRUNC;
+ /* Allow overwriting for named pipe or if overwrite option is specified. */
+ m_flags= O_WRONLY|O_CREAT|O_EXCL|O_TRUNC;
+ if (my_stat(m_path->c_ptr(), &stat_info, MYF(0)))
+ {
+ if (MY_S_ISFIFO(stat_info.st_mode))
+ m_flags= O_WRONLY;
+ else if (m_overwrite)
+ m_flags= O_WRONLY|O_TRUNC;
+ }
int ret= Stream::open();
=== modified file 'sql/backup/stream.h'
--- a/sql/backup/stream.h 2009-10-12 09:08:34 +0000
+++ b/sql/backup/stream.h 2009-10-21 12:15:53 +0000
@@ -122,7 +122,7 @@ class Output_stream: public Stream
public:
/// Constructor
- Output_stream(Logger&, ::String *, bool);
+ Output_stream(Logger&, ::String *, bool, bool);
int open();
int close();
@@ -136,6 +136,7 @@ private:
int write_magic_and_version();
bool init();
+ bool m_overwrite;
};
/// Used to read from backup stream.
=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc 2009-10-20 07:42:47 +0000
+++ b/sql/sql_parse.cc 2009-10-21 12:15:53 +0000
@@ -2401,8 +2401,11 @@ mysql_execute_command(THD *thd)
sys_var_backupdir.value_length);
backupdir.length(sys_var_backupdir.value_length);
- /* Used to specify if RESTORE should overwrite existing db with same name */
- bool overwrite_restore= false;
+ /*
+ Overwrite for RESTORE overwrites existing db with same name.
+ Overwrite for BACKUP overwrites existing backup image.
+ */
+ bool overwrite_option= false;
/* Used to specify if RESTORE should skup writing the gap event. */
bool skip_gap_event= false;
@@ -2410,8 +2413,7 @@ mysql_execute_command(THD *thd)
List<Item> lit= lex->value_list;
Item *it= 0;
- // value list only set for RESTORE in sql_yacc.yy, no error checking of
- // item necessary for backup
+ /* The value list is set for BACKUP & RESTORE options in sql_yacc.yy */
while (lit.elements)
{
it= lit.pop();
@@ -2427,7 +2429,7 @@ mysql_execute_command(THD *thd)
switch (val) {
/* OVERWRITE option */
case 1:
- overwrite_restore= true;
+ overwrite_option= true;
break;
/* SKIP GAP EVENT option */
case 2:
@@ -2439,7 +2441,7 @@ mysql_execute_command(THD *thd)
Note: execute_backup_command() sends a correct response to the client
(either ok, result set or error message).
*/
- res= execute_backup_command(thd, lex, &backupdir, overwrite_restore,
+ res= execute_backup_command(thd, lex, &backupdir, overwrite_option,
skip_gap_event);
thd->backup_in_progress= saved_backup_in_progress;
if (res)
=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy 2009-10-12 09:08:34 +0000
+++ b/sql/sql_yacc.yy 2009-10-21 12:15:53 +0000
@@ -6817,6 +6817,7 @@ backup:
TO_SYM
TEXT_STRING_sys
opt_compression
+ opt_overwrite
{
Lex->backup_dir = $6;
}
Attachment: [text/bzr-bundle] bzr/thavamuni.alagu@sun.com-20091021121553-a3uodmyff57yi6d1.bundle
| Thread |
|---|
| • bzr commit into mysql-6.0-backup branch (thavamuni.alagu:2880) Bug#36402 | Thava Alagu | 21 Oct |