Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

A place to share commonly used scripts for SQL Server Database Administrators.

Moderators

SQL Server DBA Scripts

Script to take database backup, compress it and upload to SFTP

Apr 12 2012 12:00AM by kavan dhruv   

Script to take database backup, compress it and upload to SFTP

BACKUP

declare @BACKUP varchar(200), @SQL varchar(500), @DBName varchar(100),@path varchar(100)
set @DBName = 'TestDB'
set @path = 'E:\TestDB\'
set @BACKUP = @path + @DBName +'_' + convert(varchar,getdate(),112) + '.bak'
set @SQL = 'BACKUP DATABASE ['+@DBName+'] TO DISK = '''+ @BACKUP + ''''
print (@SQL)
exec (@SQL)

ZIP

DECLARE @SERVER VARCHAR(100), @COMMAND VARCHAR(500), @FILE VARCHAR(100)
SET @SERVER = @@SERVERNAME
SET @COMMAND = '"C:\Program Files\WinRAR\RAR" a '+@BACKUP+'.rar'+' '+@BACKUP+''
print (@COMMAND)
EXEC XP_CMDSHELL @COMMAND

COPY

EXEC XP_CMDSHELL 'e:\TestDB\backupmove.bat'

This backupmove.bat file contain,

"C:\Program Files\WinSCP\WinSCP.com" -script=e:\Testdb\backupmove.txt

backupmove.txt contain

option batch on
option confirm off
open sftp://username:password@HOSTName:port
cd foldername
option transfer binary
put E:\Testdb\*.rar
close
exit

You can download WinSCP from http://winscp.net/eng/index.php


kavan dhruv
370 · 0% · 107
7
 
0
Worked
 
0
Failed
 
0
Lifesaver
 
0
Production
 
0
Unwise



Submit

2  Comments  

  • Why do people insist on using xpcmdshell when every best practices document (including the xpcmdshell topic in Books Online) recommends against its use?

    What is the point of compressing a backup if the backup itself is already compressed?

    What about encryption?

    I would think a more secure solution would be to write a SQLCLR function that handles the compression (if necessary), encryption and transport.

    commented on May 2 2012 10:21AM
    Marc Jellinek
    97 · 2% · 545
  • I agree with you Marc.

    If XP_CmdShell is enabled, you are allowing users to use all the Windows DOS command, that is not good. We can take compress backup directly in SQL Server 2008.

    commented on May 18 2012 11:14PM
    Hardik Doshi
    20 · 9% · 2839

Your Comment


Sign Up or Login to post a comment.

"Script to take database backup, compress it and upload to SFTP" rated 5 out of 5 by 7 readers
Script to take database backup, compress it and upload to SFTP , 5.0 out of 5 based on 7 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]