Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
prash.dba
Starting Member
5 Posts |
Posted - 2009-12-07 : 10:39:52
|
| DECLARE @name VARCHAR(50) -- database name DECLARE @path VARCHAR(256) -- path for backup files DECLARE @path1 VARCHAR(256) -- path for backup files DECLARE @fileName VARCHAR(256) -- filename for backup DECLARE @ZipName VARCHAR(256)DECLARE @fileDate VARCHAR(20) -- used for file name Declare @SQL nvarchar(255)SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) DECLARE db_cursor CURSOR FOR SELECT name FROM master.dbo.sysdatabases OPEN db_cursor FETCH NEXT FROM db_cursor INTO @name WHILE @@FETCH_STATUS = 0 BEGIN SET @path = 'D:\SQLBackup\'+@name+'\' SET @ZipName= @path + @name + '_' + @fileDate + '.zip' SET @fileName = @path + @name + '_' + @fileDate + '.BAK' --SET @SQL = zip @ZipName @filename Exec xp_cmdshell '''zip' @ZipName @Filename '' FETCH NEXT FROM db_cursor INTO @name END CLOSE db_cursor DEALLOCATE db_cursorHi, I wrote this script to get all database names from sysdatabases and wrote a zip command to execute in xp_cmdshell to zip the backups of all databases from their respective directories. I seem to have problem with putting single quotes in the zip command. Could any one suggest a solution for me.Thanks |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
prash.dba
Starting Member
5 Posts |
Posted - 2009-12-07 : 10:51:11
|
| Yea, The file exists, Iam getting syntax error. Thanks |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|