import java.io.*;

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),卓資企業(yè)網(wǎng)站建設(shè),卓資品牌網(wǎng)站建設(shè),網(wǎng)站定制,卓資網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,卓資網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
public class MyCopy {
public static void main(String args[]){
try {
MyCopy j = new MyCopy(); j.CopyFile(new File(args[0]),new File(args[1]));
}
catch (Exception e) {
e.printStackTrace();
}
}
public void CopyFile(File in, File out) throws Exception {
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while((i=fis.read(buf))!=-1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
}
}
// 程序運行時的命令語法為:
// javac MyCopy.java (sourcefile) (destfile)
// java MyCopy.java c:\1.txt d:\1.txt
// 當(dāng)然前提c盤1.txt 已存在。
最簡單的SQL語句:備份與還原SQL Server自帶的數(shù)據(jù)庫
在服務(wù)器上備份:
use Northwind
Backup database Northwind to disk='d:\Northwind_bak.dat' with init
RESTORE DATABASE NorthNwind FROM DISK = 'd:\Northwind_bak.dat'
備份數(shù)據(jù)庫這一操作在客戶機上實現(xiàn)
客戶機:machine
共享目錄:share (要完全共享,可寫權(quán)限)
backup:
bakcup database dbname to disk='\\machine\share\data.bak' with init
\\machine\share目錄要有寫權(quán)限。
restore:
restore database dbname from disk='\\machine\share\data.bak'
//
備注:restore 語句有很多的選項,可以查看企業(yè)管理器的在線幫助。如下
with replace, move 'dbname_dat' to 'c:\mssql7\data\dbname.mdf',
move 'dbname_log' to 'c:\mssql7\data\dbname.log'
其中'c:\mssql7\data\'是服務(wù)器的目錄,這點要注意
備份與還原數(shù)據(jù)庫的相關(guān)內(nèi)容:
SQL Server 7.0數(shù)據(jù)庫備份有四種:完全數(shù)據(jù)庫備份、增量數(shù)據(jù)庫備份、事務(wù)日志備份、數(shù)據(jù)庫文件或文件組備份。在數(shù)據(jù)庫崩潰時,應(yīng)該首先嘗試備份事務(wù)日志(這一點很重要),然后恢復(fù)最后的數(shù)據(jù)庫備份、該次數(shù)據(jù)庫備份后的所有增量備份,最后恢復(fù)事務(wù)日志備份,這樣可以將數(shù)據(jù)庫恢復(fù)到崩潰前的狀態(tài)。
備份是定期的,而不是實時的,所以利用備份并不能完全恢復(fù)數(shù)據(jù)庫,它只能將數(shù)據(jù)庫恢復(fù)到制作備份的那一刻 ...... 數(shù)據(jù)庫日志是實時的,他忠實的記錄下所有對數(shù)據(jù)庫的更新操作。因此,當(dāng)磁盤出現(xiàn)故障造成數(shù)據(jù)庫損壞時,就可以首先利用備份恢復(fù)數(shù)據(jù)庫(大部分數(shù)據(jù)),然后運行數(shù)據(jù)庫日志,即將備份后所做的操作重新在做一遍,從而將數(shù)據(jù)庫完全恢復(fù)。
--備份完整的數(shù)據(jù)庫---------------------------------------------------------------
//創(chuàng)建一個備份設(shè)備:
1. Create the backup device for the full MyNwind backup.///
USE master
EXEC sp_addumpdevice 'disk', 'MyNwind_2', 'c:\mssql7\backup\MyNwind_2.dat'
2. Back up the full MyNwind database.
BACKUP DATABASE MyNwind TO MyNwind_2
--備份數(shù)據(jù)庫的日志---------------------------------------------------------------
--1. Create the log backup device.
USE master
EXEC sp_addumpdevice 'disk', 'MyNwindLog1', 'c:\mssql7\backup\MyNwindLog1.dat'
--2. Update activity has occurred before this point. Back up the log of the MyNwind database.
BACKUP LOG MyNwind TO MyNwindLog1
try
AdoQuery1.Close;
AdoQuery1.SQL.Clear;
AdoQuery1.SQL.Add('backup database pubs');
AdoQuery1.SQL.Add('to disk='+''''+edtPath.Text+'''');
AdoQuery1.ExecSQL;
except
ShowMessage('備份數(shù)據(jù)庫失敗!');
exit;
end;
SQL server的備份
=========================================================================
=========================================================================
備份:
with adocommand_restore do//用ADocommand控件
begin
CommandText:='use Master';//
Execute;
CommandText:='execute sp_helpdevice';//系統(tǒng)存儲過程
Execute ;
CommandText:='backup database '+'db_name'+' to disk='''+FileName+''' with init';//這行應(yīng)當(dāng)是這樣
Execute ;
CommandText:='Use '+'db_name';//這行應(yīng)當(dāng)是這樣
Execute ;
application.MessageBox('已經(jīng)成功備份數(shù)據(jù)庫','數(shù)據(jù)庫備份',MB_OK + MB_ICONINFORMATION);
end;
恢復(fù):
with adocommand1 do//用AdoCommand控件
begin
CommandText:='use Master';
Execute;
CommandText:='execute sp_helpdevice';
Execute ;
CommandText:='Restore database '+'db_name'+' From disk='''+'c:\data1.bak'+''' with replace';//這行應(yīng)當(dāng)是這樣
Execute ;
CommandText:='Use '+'db_name';//這行應(yīng)當(dāng)是這樣
Execute ;
application.MessageBox('已經(jīng)成功恢復(fù)數(shù)據(jù)庫','數(shù)據(jù)庫恢復(fù)',MB_OK + MB_ICONINFORMATION);
end;
*注:db_name指數(shù)據(jù)庫的名稱
將MySql中的數(shù)據(jù)庫導(dǎo)出到文件中 備份
import java.io.*;
import java.lang.*;
public class BeiFen {
public static void main(String[] args) {
// 數(shù)據(jù)庫導(dǎo)出
String user = "root"; // 數(shù)據(jù)庫帳號
String password = "root"; // 登陸密碼
String database = "test"; // 需要備份的數(shù)據(jù)庫名
String filepath = "e:\\test.sql"; // 備份的路徑地址
String stmt1 = "mysqldump " + database + " -u " + user + " -p"
+ password + " --result-file=" + filepath;
/*
* String mysql="mysqldump test -u root -proot
* --result-file=d:\\test.sql";
*/
try {
Runtime.getRuntime().exec(stmt1);
System.out.println("數(shù)據(jù)已導(dǎo)出到文件" + filepath + "中");
}
catch (IOException e) {
e.printStackTrace();
}
}
}
將數(shù)據(jù)從磁盤上的文本文件還原到MySql中的數(shù)據(jù)庫
import java.io.*;
import java.lang.*;
/*
* 還原MySql數(shù)據(jù)庫
* */
public class Recover {
public static void main(String[] args) {
String filepath = "d:\\test.sql"; // 備份的路徑地址
//新建數(shù)據(jù)庫test
String stmt1 = "mysqladmin -u root -proot create test";
String stmt2 = "mysql -u root -proot test " + filepath;
String[] cmd = { "cmd", "/c", stmt2 };
try {
Runtime.getRuntime().exec(stmt1);
Runtime.getRuntime().exec(cmd);
System.out.println("數(shù)據(jù)已從 " + filepath + " 導(dǎo)入到數(shù)據(jù)庫中");
} catch (IOException e) {
e.printStackTrace();
}
}
}
分享標題:java代碼日志文件備份 java寫日志文件
文章地址:http://www.chinadenli.net/article44/dooshee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站制作、自適應(yīng)網(wǎng)站、網(wǎng)站設(shè)計、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)