richa1960
asked on
A daily full backup that creates multiple files that are seperated for each day
I'd like to take a current multi file sql backup and have the process run and create the 3 files but not in an appended fashion.
but with each days run being separated, or shown. the code I'm using is below but it only appends the backup into each files
not separated by date.
BACKUP DATABASE [IFS_FSM] TO DISK = N'C:\SQL_backup_tst\IFS_FS M_FILE1.BA K',
DISK = N'C:\SQL_backup_tst\IFS_FS M_FILE2.BA K',
DISK = N'C:\SQL_backup_tst\IFS_FS M_FILE3.BA K'
WITH NOFORMAT, NOINIT, NAME = N'IFS_FSM-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
but with each days run being separated, or shown. the code I'm using is below but it only appends the backup into each files
not separated by date.
BACKUP DATABASE [IFS_FSM] TO DISK = N'C:\SQL_backup_tst\IFS_FS
DISK = N'C:\SQL_backup_tst\IFS_FS
DISK = N'C:\SQL_backup_tst\IFS_FS
WITH NOFORMAT, NOINIT, NAME = N'IFS_FSM-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
ASKER
I'm only dealing with a couple vary large databases that I want to backup but to speed up the process create split backup files, so instead of one large backup file of 100+gb it breaks it down into 25GB 4 file set. there is a way to do it with the code I'd sent but that will append for each run and not separate out each days run for the 4 files
or try just for your DB (use INIT to overwrite)
code
code
use master;
go
DECLARE @dbName varchar(100)='IFS_FSM'
DECLARE @backupPath varchar(100);
DECLARE @backupQuery varchar(500);
DECLARE @DT varchar(50)
set @DT = REPLACE(REPLACE( convert(varchar, getdate(), 109), ':', '-') ,' ','_')
-- make sure that the below path exists
set @backupPath = 'C:\SQL_backup_tst\'
-- Backup SQL statement
set @backupQuery = 'backup database ' + @dbName + ' to disk = ''' + @backupPath + @dbName + '_FILE1_'+@DT+'.bak, disk = ''' + @backupPath + @dbName + '_'+@DT+'.bak,
disk = ''' + @backupPath + @dbName + '_FILE2_'+@DT+'.bak, disk = ''' + @backupPath + @dbName + '_FILE3_'+@DT+'.bak
WITH NOFORMAT, INIT, NAME = N''IFS_FSM-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD, STATS = 10'''
-- Print SQL statement
print @backupQuery
-- Execute backup script
EXEC (@backupQuery)
I believe the following script should do it for you:
USE master
GO
EXEC sp_addumpdevice 'disk', 'File1', 'C:\SQL_backup_tst\IFS_FSM _FILE1.BAK '
EXEC sp_addumpdevice 'disk', 'File2', 'C:\SQL_backup_tst\IFS_FSM _FILE2.BAK '
EXEC sp_addumpdevice 'disk', 'File3', 'C:\SQL_backup_tst\IFS_FSM _FILE3.BAK '
BACKUP DATABASE [IFS_FSM]
TO File1, File2, File3
WITH NOINIT
USE master
GO
EXEC sp_addumpdevice 'disk', 'File1', 'C:\SQL_backup_tst\IFS_FSM
EXEC sp_addumpdevice 'disk', 'File2', 'C:\SQL_backup_tst\IFS_FSM
EXEC sp_addumpdevice 'disk', 'File3', 'C:\SQL_backup_tst\IFS_FSM
BACKUP DATABASE [IFS_FSM]
TO File1, File2, File3
WITH NOINIT
ASKER
with the 'EXEC sp_adddumpdevice ' I end up with a file already exists error when it runs again, so I wouldn't be able to maintain multiple days of the file grouping.
ASKER
EugeneZ I got the following error, so I'm picking through it to see where the issue is.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '\'.
Msg 132, Level 15, State 1, Line 2
The label 'C' has already been declared. Label names must be unique within a query batch or stored procedure.
Msg 319, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Msg 105, Level 15, State 1, Line 3
Unclosed quotation mark after the character string ''.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '\'.
Msg 132, Level 15, State 1, Line 2
The label 'C' has already been declared. Label names must be unique within a query batch or stored procedure.
Msg 319, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Msg 105, Level 15, State 1, Line 3
Unclosed quotation mark after the character string ''.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works like a charm, thanks.
T-SQL script to backup all user databases with time stamped backup file.
http://blogs.msdn.com/b/ai/archive/2012/05/29/t-sql-script-to-backup-all-user-databases-with-time-stamped-backup-file.aspx
Open in new window