Help - Search - Members - Calendar
Full Version: HOWTO: Backup script for MSSQL & Disksync; same filename
The Planet Forums > System Administration > Backups, Restores and Transfers
Matt2k
This is the backup script I'm using on my windows servers. The built in maintenance plan utility schedules MSSQL backups nicely, but the backup file names are timestamped which causes DiskSync to record them as an entirely new file. This script backs up every database to the exact same file name to minimize storage requirements and backup times.

I have a few databases greater than 2GB, so this saves me quite a lot on DiskSync requirements. Instead of 2GB * 7 days == 14GB, I have 2GB with seven days of delta blocks each day (probably no more than 100MB a day)

I would probably stick this stored procedure in your master database, then schedule a nighly job through the SQL Server Agent to run this a little before your DiskSync kicks in. I don't see a lot of potential for abuse, but you should verify that only the account running the SQL agent has execute permission on this procedure.

You will probably still want to keep the maintenance plan around for the database optimizations and integrity checks and stuff, since this script doesn't deal with any of that.

Also, please be experienced enough to examine the backup folder and make sure this script runs. If you're not comfortable enough with MS-SQL to know what I'm talking about here, you should probably stick with the maintenance plans for backup. Read: I'm not responsible for any loss of data incurred by relying on this script.

Execute this code through your query analyzer while attached to a database (I suggest 'master')

CODE
CREATE Procedure spBackupAlldatabases

as



declare cur_databases cursor for

select name from master..sysdatabases where name not in ('tempdb')



open cur_databases



declare @spath varchar(100), @sDBName varchar(100), @sBackupPath varchar(100), @cleardbs varchar(100)

set @sPath = 'C:Program FilesMicrosoft SQL ServerMSSQLBACKUP'



-- Clear out backups in this folder

-- Uncomment if you like (clears out databases that have since been removed)

-- However this may defeat the purpose of this script, since the creation dates will have changed on all files

-- set @cleardbs = 'del "' + @sPath + '*.bak"'

-- exec master..xp_cmdshell @cleardbs



fetch next  from cur_databases into @sDBName



While (@@fetch_status = 0)

BEGIN

    set @sBackupPath = @sPath + @sDBName + '.bak'

    backup database @sDBName to disk = @sBackupPath with init

    fetch next  from cur_databases into @sDBName

END



close cur_databases

deallocate cur_databases

GO


Then schedule a task that is simply

CODE
Exec spBackupAlldatabases
jscott
Thanks, Matt, for taking the time to go into detail as to how you do this. I will sticky this post to help newcomers find it more easily.
Advanced Intellect
Thanks Matt.

Very useful

wink.gif
DarkIncubuS
Indeed Thank You alot for the script , helped alot icon_smile.gif
Rubal
Nice Script Matt.

Thanks for Sharing icon_smile.gif
netcommander
how can use linux server, can you write for linux
kind regards
jscott
Linux does not run MS-SQL.
netcommander
yes I know so sorry bad question I would you like to learn how can I backup my mysql with disksync
kind regards
jscott
Greetings,

MySQL with DiskSync was briefly discussed here:

http://forums.theplanet.com/index.php?show...80&hl=mysql

Essentially one must follow best practice for whatever application they are utilizing, regardless of what backup technology is being used to protect items at the filesystem or disk level.
netcommander
thanks for help
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.