Précédent   Forum des professionnels en informatique > Bases de données > PostgreSQL
PostgreSQL Forum PostgreSQL. Avant de poster -> F.A.Q PostGreSQL Tutoriels PostGreSQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 24/10/2006, 14h36   #1
Membre actif
 
Avatar de Empty_body
 
Inscription : mai 2004
Messages : 679
Détails du profil
Informations forums :
Inscription : mai 2004
Messages : 679
Points : 186
Points : 186
Par défaut Synchroniser 2 DB.

Salut,
Je suis à la recherche d'un outil de synchronisation postgres qui soit un freeware... Quelqu'un aurait qqch à me proposer???
Merci.
__________________
Pourquoi vouloir ré-inventer la roue...
...Surtout si c'est pour la faire carrée...
Empty_body est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/10/2006, 16h25   #2
Membre actif
 
Avatar de Empty_body
 
Inscription : mai 2004
Messages : 679
Détails du profil
Informations forums :
Inscription : mai 2004
Messages : 679
Points : 186
Points : 186
En fait, je me suis sans doute mal exprimé dans ma demande... Ce que je cherche, c'est un freeware qui me permette de sélectionner une table de ma db ou plusieurs ou toutes et d'obtenir un fichier contenant toutes les lignes nécessaires pour dumper la ou les tables sélectionnées...
Merci.
__________________
Pourquoi vouloir ré-inventer la roue...
...Surtout si c'est pour la faire carrée...
Empty_body est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/10/2006, 09h19   #3
Membre actif
 
Avatar de Empty_body
 
Inscription : mai 2004
Messages : 679
Détails du profil
Informations forums :
Inscription : mai 2004
Messages : 679
Points : 186
Points : 186
J'ai trouvé mon bonheur en le créant en java...
Voici la source pour les curieux... (elle est pas encore top niveau finition mais elle fonctionne nickel...)
Code :
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
 
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.Iterator;
 
public class GenerateExportScript {
 
	private String myDB;
	private String myHost;
	private String myTable;
 
	private Connection myConnexion;
 
	private String driversPost = "org.postgresql.Driver";
	private String urlPost = "jdbc:postgresql://";
	static private String baseDir;
	static private File outputDirect;
 
	StringBuffer outputWithData = new StringBuffer();
	StringBuffer outputWithoutData = new StringBuffer();
	StringBuffer outputWithDataImport = new StringBuffer();
	StringBuffer outputWithoutDataImport = new StringBuffer();
 
	public static void main(String[] args){
		String myHost = "127.0.0.1";
 
		baseDir = "C:\\Dump"+myHost+"\\";
		outputDirect = new File(baseDir);
 
		//String[] listTableDB = { "ma_DB","ma_Table" };
		String[] listTableDB = { "Ma_DB","#all" };
 
		new GenerateExportScript(myHost, listTableDB[0], listTableDB[1]);
 
}
 
	public GenerateExportScript(String myHost, String myDB, String myTable) {
		this.myDB = myDB;
		this.myHost = myHost;
		this.myTable = myTable;
 
		try {
 
			Class.forName(driversPost);
			myConnexion = DriverManager.getConnection(urlPost + myHost + ":5432/" + myDB, "User", "Pass");
			System.out.println("Batch file body");
			String host;
			IF ("127.0.0.1".equals(myHost)){
				host = "";
			}else{
				host = "-h "+myHost;
			}
			File directory = NULL;
			File directoryData = NULL;
			directory = new File(outputDirect, myDB);
			directory.mkdirs();
			directoryData = new File(directory, "Data");
			directoryData.mkdirs();
 
			IF(myTable == "#all"){
				HashMap tablesFirst = getTables(myConnexion);
				Iterator listTBF = tablesFirst.keySet().iterator();
				while (listTBF.hasNext()) {
					String TABLE = (String) listTBF.next();
					dumpCommand(TABLE);
				}
 
			}else{
				dumpCommand(myTable);
			}
			File batFileData = new File(directoryData, "Dump.bat");
			FileOutputStream batFileDataOS = new FileOutputStream(batFileData);
			System.out.println(outputWithData.toString());
			batFileDataOS.WRITE(outputWithData.toString().getBytes());
			batFileDataOS.FLUSH();
			batFileDataOS.close();
			//------
			File batFileDataImport = new File(directoryData, "Import.bat");
			FileOutputStream batFileDataOSImport = new FileOutputStream(batFileDataImport);
			System.out.println(outputWithDataImport.toString());
			batFileDataOSImport.WRITE(outputWithDataImport.toString().getBytes());
			batFileDataOSImport.FLUSH();
			batFileDataOSImport.close();
 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 
	public void dumpCommand(String myTable){
		this.myTable = myTable;
		outputWithData.append("pg_dump -D -U arthur "+myHost+" -c -t"+myTable+" "+myDB+" > "+myTable+".sql");
		outputWithData.append('\r');
		outputWithData.append('\n');
			}
 
	private HashMap getTables(Connection conn) throws SQLException{
		HashMap TABLES = new HashMap();
		DatabaseMetaData dbMD = conn.getMetaData();
		String[] types = { "TABLE", "" };
		ResultSet res = dbMD.getTables("public", "", NULL, types);
		while (res.next()) {
			String tableName = res.getString("table_name");
			HashMap FIELDS = new HashMap();
 
			ResultSet res2 = dbMD.getColumns("public", "", tableName, NULL);
			while (res2.next()) {
				String COLUMN = res2.getString("COLUMN_NAME");
				int type = res2.getInt("DATA_TYPE");
				int size = res2.getInt("COLUMN_SIZE");
				int decimal = res2.getInt("DECIMAL_DIGITS");
				String deff = res2.getString("COLUMN_DEF");
				String comment = res2.getString("REMARKS");
				String typeName = res2.getString("TYPE_NAME");
				FIELDS.put(COLUMN, new FIELD(type, size, decimal, typeName, deff, comment));
			}
			TABLES.put(tableName, FIELDS);
		}
		RETURN TABLES;
	}
 
	private class FIELD {
 
		private int type;
		private int size;
		private int decimal;
		private String typeName;
		private String deff;
		private String remark;
 
		public int getSize(){
			RETURN size;
		}
 
		public int getType(){
			RETURN type;
		}
 
		public FIELD(int type, int size, int decimal, String typeName, String deff, String remark) {
			this.size = size;
			this.decimal = decimal;
			this.type = type;
			this.typeName = typeName;
			this.deff = deff;
		}
		public String toString(){
			RETURN "type=" + type + ", size=" + size + ", decimal=" + decimal + ", Type Name=" + typeName + ", Default Value=" + deff;
		}
		public BOOLEAN equals(Object obj){
			IF (obj instanceof FIELD) {
				FIELD cp = (FIELD) obj;
				RETURN (cp.getType() == type && cp.getSize() == size);
			} else {
				RETURN false;
			}
		}
 
		public String getDeff(){
			RETURN deff;
		}
 
		public String getTypeName(){
			RETURN typeName;
		}
 
		public int getDecimal(){
			RETURN decimal;
		}
 
		public String getRemark(){
			RETURN remark;
		}
	}
}
Si on veut un dump de toutes les tables, il suffit de choisir #all sinon, on commente cette ligne et on note le nom de la DB et on décommente la ligne adéquate...
__________________
Pourquoi vouloir ré-inventer la roue...
...Surtout si c'est pour la faire carrée...
Empty_body est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/10/2006, 12h28   #4
Membre chevronné
 
Avatar de Spoutnik
 
Homme
Inscription : octobre 2003
Messages : 668
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Etats-Unis

Informations forums :
Inscription : octobre 2003
Messages : 668
Points : 746
Points : 746
Hello

il y a un petit outil qui s'appele pg_dump et qui fait exactement ce que tu cherchais à faire ^^.
Et en plus il est fournit en standart avec le paquet client il me semble


++
__________________
Two beer or not two beer. (Shakesbeer)
Question technique par MP => poubelle!
Spoutnik est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 06h43.


 
 
 
 
Partenaires

Hébergement Web