Powerbuilderデータベースのバックアップとリカバリ

1788 ワード

バックアップ:
string backup
STRING pathstring 
int li_net
if GetFilesaveName(" ",pathstring,backup,"bak","bak (*.bak),*.bak") = 1 then

	if pathstring = '' then 
		messagebox(" "," !") 
		return 
	end if
	IF FileExists ( pathstring ) THEN  
		li_net=Messagebox(' ',' : "'+pathstring+'" .~r~n~n ?',Question!,YesNo!) 
		IF li_net= 1 THEN   
			FileDelete ( pathstring ) 
		ELSE
			return
		END IF 
	end if
	setpointer(hourglass!)
	backup= "backup database "+sqlca.database+" to disk = " + "'" + pathstring + "'"; 
	sqlca.AutoCommit = true
	EXECUTE IMMEDIATE :backup;
	setpointer(arrow!)
	if sqlca.sqlcode = 0 then 
		messagebox(' ',' !') 
	else 
		messagebox(" ",sqlca.sqlerrtext) 
	end if
	SQLCA.AutoCommit = false 
end if

リカバリ:
string backup
STRING pathstring 
if GetFileopenName(" ",pathstring,backup,"bak","bak (*.bak),*.bak") = 1 then

	if pathstring = '' then 
		messagebox(" "," !") 
		return 
	end if
	sqlca.AutoCommit = true
	backup="ALTER DATABASE "+sqlca.database+" SET OFFLINE WITH ROLLBACK IMMEDIATE";
	EXECUTE IMMEDIATE :backup;
	backup= "use master restore database "+sqlca.database+" from disk='" +pathstring+ "' with replace"; 
	
	EXECUTE IMMEDIATE :backup; 
	if sqlca.sqlcode = 0 then 
		messagebox(' ',' !') 
	else 
		messagebox(" "," +"+sqlca.sqlerrtext) 
	end if
	sqlca.autocommit=false

	
	backup="ALTER  database “+sqlca.database+" set   online  ";
	EXECUTE IMMEDIATE :backup;

	disconnect;
	connect;	// , 
end if