2008年1月9日 星期三

完整備份SQLServer

http://www.sqldbatips.com/showarticle.asp?ID=37

using Microsoft.SqlServer.Management.Smo;

namespace SMOTest
{
class Program
{
static void Main()
{
Server svr = new Server();
Backup bkp = new Backup();
bkp.Devices.AddDevice(@"C:\SMOTest.bak", DeviceType.File);
bkp.Database = "SMO";
bkp.Action = BackupActionType.Database;
bkp.Initialize = true;
bkp.PercentCompleteNotification = 10;
bkp.PercentComplete += new PercentCompleteEventHandler(bkp_PercentComplete);
bkp.SqlBackup(svr);
}

static void bkp_PercentComplete(object sender, PercentCompleteEventArgs e)
{
Console.WriteLine(e.Percent.ToString() + "% backed up");
}
}
}

沒有留言: