-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBSync.cpp
93 lines (77 loc) · 3.52 KB
/
DBSync.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*----------------------------------------------------------------------
Copyright (c) Dan Petitt, http://www.coderanger.com
All Rights Reserved.
Please see the file "licence.txt" for licencing details.
File: DBSync.cpp
Owner: [email protected]
Purpose: Generates a SQL database of SQL Statements describing the
differences between two mySQL databases
----------------------------------------------------------------------*/
#include "stdafx.h"
#include "TableCompareStream.h"
#include "TableCompareQuery.h"
int _tmain(int argc, _TCHAR* argv[])
{
_tprintf( _T("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n") );
_tprintf( _T("MySQL DBSync (c) Copyright 2010 Coderanger.com. All rights reserved.\n\n") );
_tprintf( _T("DBSync takes two mySQL databases and compares the data in each table so as to\n") );
_tprintf( _T("create a SQL 'differences' file that can be run on the target db to bring it\n") );
_tprintf( _T("into sync with the source database. This can use a lot of memory so use 64bit.\n\n") );
_tprintf( _T("Usage:\n") );
_tprintf( _T("dbsync64.exe (parameters as below all are required):\n") );
_tprintf( _T("\t<sourcehost> <sourceport> <sourceuser> <sourcedbname> <sourcepass>\n") );
_tprintf( _T("\t<targethost> <targetport> <targetuser> <targetpass> <targetdbname>\n") );
_tprintf( _T("\t<showprogress: true|false>\n") );
_tprintf( _T("\t<exportfilepath>\n") );
_tprintf( _T("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n") );
if( argc != 13 )
{
_tprintf( _T("ERROR: Number of arguments passed in were wrong, expecting 12\n") );
return EXIT_FAILURE;
}
LPCTSTR pcszSourceHost = argv[ 1 ];
UINT uSourcePort = _tstoi( argv[ 2 ] );
LPCTSTR pcszSourceUser = argv[ 3 ];
LPCTSTR pcszSourcePassword = argv[ 4 ];
LPCTSTR pcszSourceDB = argv[ 5 ];
LPCTSTR pcszTargetHost = argv[ 6 ];
UINT uTargetPort = _tstoi( argv[ 7 ] );
LPCTSTR pcszTargetUser = argv[ 8 ];
LPCTSTR pcszTargetPassword = argv[ 9 ];
LPCTSTR pcszTargetDB = argv[ 10 ];
bool bShowProgress = true;
if( !_tcsicmp( argv[ 11 ], _T("false") ) )
{
bShowProgress = false;
}
LPCTSTR pcszExportFilePath = argv[ 12 ];
_tprintf( _T("Syncing between source db: %s and target db: %s\n\n"), pcszSourceDB, pcszTargetDB );
try
{
if( !_tcsicmp( pcszSourceHost, pcszTargetHost ) && uSourcePort == uTargetPort )
{
_tprintf( _T("Source and target on same server, using the Fast Query Analysis Algorithm\n\n") );
// Same server so use the faster, more efficient query based method
CTableCompareQuery tblQuery;
tblQuery.SetSourceDatabase( pcszSourceHost, pcszSourceUser, pcszSourcePassword, pcszSourceDB, uSourcePort );
tblQuery.SetTargetDatabase( pcszTargetHost, pcszTargetUser, pcszTargetPassword, pcszTargetDB, uTargetPort );
tblQuery.Start( pcszExportFilePath, bShowProgress, true );
}
else
{
_tprintf( _T("Source and target on different servers, using the Memory Based Analysis Algorithm\n\n") );
// Different servers so use the slower, memory hugging load everything into ram method
CTableCompareStream tblStream;
tblStream.SetSourceDatabase( pcszSourceHost, pcszSourceUser, pcszSourcePassword, pcszSourceDB, uSourcePort );
tblStream.SetTargetDatabase( pcszTargetHost, pcszTargetUser, pcszTargetPassword, pcszTargetDB, uTargetPort );
tblStream.Start( pcszExportFilePath, bShowProgress, true );
}
}
catch( XMySQL::CException *e )
{
_tprintf( _T("ERROR: (%d) %s\n"), e->GetErrorCode(), e->GetError() );
delete e;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}