Full Backup Script With Device


/ Published in: SQL
Save to your folder(s)

Crear un backup de una base de datos en SQL Server 2005/08 desde código en la posición definida por Device.

Cuidado con los permisos:
http://support.microsoft.com/kb/207187/es


Copy this code and paste it in your HTML
  1. USE [master] ;
  2.  
  3. /* PRIVATE FIELD(s) */
  4. DECLARE @DATABASE SYSNAME ;
  5. DECLARE @FilePath NVARCHAR(500) ;
  6. DECLARE @FileName NVARCHAR(500) ;
  7. DECLARE @BackupName NVARCHAR(500) ;
  8. DECLARE @DeviceName NVARCHAR(500);
  9.  
  10. /* FILL FIELD(s) */
  11. SELECT @DATABASE = 'DATA BASE NAME'
  12. SELECT @FilePath = N'D:\Backup\';
  13. SELECT @FileName = @FilePath + @Database + '.bak' ;
  14. SELECT @DeviceName = @Database + '_' + 'dump';
  15.  
  16. /* CREATE BACKUP DEVICE */
  17. IF (SELECT COUNT(*) FROM sys.backup_devices WHERE NAME=@DeviceName)<=0
  18. BEGIN
  19. EXEC sp_addumpdevice 'disk', @DeviceName, @FileName;
  20. END
  21.  
  22. /* BACKUP DATABASE */
  23. BACKUP DATABASE @Database TO @DeviceName
  24. GO

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.