Created
February 6, 2015 09:05
-
-
Save raducugheorghe/c4b208cd2842c68a0c7d to your computer and use it in GitHub Desktop.
[TransactSQL] Backup website and database from SQL job (uses winrar)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Map network drive | |
EXEC XP_CMDSHELL 'net use W: \\mainstore\Backup PASSWORD /user:USERNAME' | |
2. Backup Database | |
declare | |
@timestamp varchar(8), | |
@fileName varchar(1024) | |
SELECT @timestamp = CONVERT(VARCHAR(8), GETDATE(), 112) | |
select @fileName = N'W:\APPS\Databases\DBNAME_' + @timestamp +'.bak' | |
BACKUP DATABASE DBNAME | |
TO DISK =@filename | |
3. Backup Site | |
EXEC XP_CMDSHELL '"C:\Program Files\WinRAR\Rar.exe" a -ag W:\APPS\WebSites\SITENAME_.rar I:\WebSites\SITENAME' | |
4. Disconnect Network Drive | |
EXEC XP_CMDSHELL 'net use W: /DELETE' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment