sqlserver backup use jobs and clear history backup file, restore database
2014-01-21 09:26
260 查看
一、sqlserver备份到本地磁盘以及清除超过三天的本分文件
1.sqlserver——sql server agent——jobs——new 新建一个用来备份的工作
2.——general——输入name
3.——step——new——输入name/选择database/command如下:
declare @strPath nvarchar(255)/*备份到E盘backup文件夹以DB+日期+.bak命名*/
set @strPath='E:\BackUp\DB'+convert(nvarchar(8),getdate(),112)+'.bak'
backup database[AHU_A3] to disk=@strPath with noinit,nounload,noskip,stats=10,noformat
declare @delPath nvarchar(255)/*删除超过三天的备份*/
set @delPath='E:\BackUp\DB'+convert(nvarchar(8),getdate()-3,112)+'.bak'
declare @cmd nvarchar(255)
set @cmd='del '+@delPath
exec master..xp_cmdshell @cmd
在删除备份之前
select * from sys.configurations where name='xp_cmdshell'
首先查看xp_cmdshell的value值,如果是1,则可以删除文件,如果为0,则需要修改它的值
执行下面的SQL语句即可:
EXEC sp_configure 'show advanced options',1
GO
reconfigure
go
exec sp_configure 'xp_cmdshell',1
go
reconfigure
go
--开启数据库删除文件的权限
4.——schedules设定备份计划
5.start jobs at step
二、数据库还原
1.tasks——restore——database
2.general——source——device——*.bak——restore
option——OverWrite The Exting Database
3.ok
1.sqlserver——sql server agent——jobs——new 新建一个用来备份的工作
2.——general——输入name
3.——step——new——输入name/选择database/command如下:
declare @strPath nvarchar(255)/*备份到E盘backup文件夹以DB+日期+.bak命名*/
set @strPath='E:\BackUp\DB'+convert(nvarchar(8),getdate(),112)+'.bak'
backup database[AHU_A3] to disk=@strPath with noinit,nounload,noskip,stats=10,noformat
declare @delPath nvarchar(255)/*删除超过三天的备份*/
set @delPath='E:\BackUp\DB'+convert(nvarchar(8),getdate()-3,112)+'.bak'
declare @cmd nvarchar(255)
set @cmd='del '+@delPath
exec master..xp_cmdshell @cmd
在删除备份之前
select * from sys.configurations where name='xp_cmdshell'
首先查看xp_cmdshell的value值,如果是1,则可以删除文件,如果为0,则需要修改它的值
执行下面的SQL语句即可:
EXEC sp_configure 'show advanced options',1
GO
reconfigure
go
exec sp_configure 'xp_cmdshell',1
go
reconfigure
go
--开启数据库删除文件的权限
4.——schedules设定备份计划
5.start jobs at step
二、数据库还原
1.tasks——restore——database
2.general——source——device——*.bak——restore
option——OverWrite The Exting Database
3.ok
相关文章推荐
- 在MSDB中清除SQL Server 还原备份历史数据(Purging MSDB Backup and Restore History from SQL Server)
- [SQL Server][FILESTREAM] -- How to Backup and Restore a SQL Server FILESTREAM Enabled Database
- How to see all the application errors related to SQL Server and export them to a .csv file.
- 海洋工作室——网站建设专家:The version of SQL Server in use does not support datatype datetime2 and the Entity Framework.
- Saving and Displaying Photos in SQL Server using ASP.NET and FileUpload Control
- SQL Server Database Backup and Restore in C#
- backup and restore database on Microsoft SQL Server 2005
- Check SQL Server Backup History Record
- FILESTREAM Configuration and Setup Changes in SQL Server 2008 February CTP
- filegroup reference and partitioning scheme' is not supported in this version of sql server.
- How to use Trusted Connection when SQL server and web Server are on two separate machines.
- Check SQL Server Backup History Record
- SQL Server Backup file in standard Zip format
- Determine SQL Server memory use by database and object
- [SQL Server][FILESTREAM] -- How to Detach and Attach a SQL Server FILESTREAM Enabled Database
- file,filegroup and tempdb in sqlserver
- [SQL Server][FILESTREAM] -- Using INSERT, UPDATE and DELETE to manage SQL Server FILESTREAM Data
- How to backup and restore database in SQL Server
- Checking to make sure a SQL Server backup is useable
- SQLBackupAndFTP The server principal "NT AUTHORITY\SYSTEM" is not able to access the database "xxxx"