SqlServer 自动备份日志 SQL 形式

USE [KYC] 
GO


--完整备份
backup database [KYC] to disk='D:\DbBackUp\KYC.bak' WITH init;
GO
-- 备份日志信息
backup log [KYC] to disk='D:\DbBackUp\KYC.log' WITH init;
GO


USE	[KYC]
GO


--设置为简单模式
ALTER DATABASE [KYC] SET RECOVERY SIMPLE WITH NO_WAIT
GO
ALTER DATABASE [KYC] SET RECOVERY SIMPLE   
GO
-- 查询出日志文件的名称
DECLARE @LogFileName nvarchar(500)
select @LogFileName=name from SYS.database_files where type_desc='LOG'
DBCC SHRINKFILE (@LogFileName, 1, TRUNCATEONLY)
GO
USE[KYC]
GO
--还原为完全模式
ALTER DATABASE [KYC] SET RECOVERY FULL WITH NO_WAIT
GO
ALTER DATABASE [KYC] SET RECOVERY FULL  
GO




-- 查询数据库日志文件的路径
-- select database_id,name,physical_name AS CurrentLocation,state_desc,size from sys.master_files where database_id=db_id(N'WmsExpress');
相关文章
相关标签/搜索