一連のRDBMSインスタンス間のデータ移動関係シリーズ
今回はOracle版メモ。
移行元サーバからデータをエクスポート
exp "db_username/db_password@from_server file=dump.dmp tables=(table_a, table_b)"
移行先サーバへデータをインポート
imp "db_username/db_password@distination file=dump.dmp tables=(table_a, table_b)"
FormFile ( org.apache.struts.upload.FormFile ) をファイルに書き出す
private void _saveFormFile(String filePath, FormFile upfile) throws Exception
{
InputStream is = upfile.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
FileOutputStream fos = new FileOutputStream(filePath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
int read = 0;
while ((read = bis.read()) != -1) {
bos.write(read);
}
bos.flush();
bis.close();
bos.close();
}
書き出したファイルをArrayListに格納する
private ArrayList _readFile(String filePath) throws Exception
{
File file = new File(filePath);
FileInputStream fis = new FileInputStream(filePath);
InputStreamReader isr = new InputStreamReader(fis, "utf-8"));
BufferedReader br = new BufferedReader(isr);
ArrayList lines = new ArrayList();
String line = br.readLine();
while(line != null){
lines.add(line);
line = br.readLine();
}
br.close();
return lines;
}
Listに格納されたテキストをファイルに書き出す
private void _saveFile(String filePath, List lines) throws Exception
{
File file = new File(filePath);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath),"utf-8"));
for (Iterator i = lines.iterator(); i.hasNext();) {
bw.write((String)i.next());
bw.newLine();
bw.flush();
}
bw.close();
return;
}
参考サイト
http://www.ingrid.org/jajakarta/struts/struts1.0/ja/target/documentation/api/index.html
http://www.javaroad.jp/opensource/js_struts20.htm
これも良く忘れるのでメモ。
PostgreSQLのダンプって、DDLとDMLをまんま吐いてくれるから便利。
リモートからやる場合は、PostgreSQLのバージョンをあわしておく必要がある。
移行先サーバにログイン
ssh username@destination_server
移行元サーバからデータをダンプ
pg_dump -U db_username -h fromserver -d db_name -p db_password -f ./dump.sql -v
ダンプしたデータをリストア
psql -U db_username -h localhost -d db_name < ./dump.sql