November 2, 2010 at 7:05 am
I'm new to SQL and we have an SQLExpress database that we need to backup on a nightly basis. Is there a backup process with SQLExpress or will the Windows Server Backup process include the database if we point it to SQL location..?? Thank you..!!
November 2, 2010 at 7:12 am
With SQLExpress you don't have SQLAgent to run backups. You have to manually set up a Windows Scheduled Task to run a backup command.
A simple filesystem backup won't help in case you need to restore a database: you have to backup the database, not its files.
-- Gianluca Sartori
November 2, 2010 at 7:20 am
Do you mean like a Batch(.bat) file to run...??? Is there an example anywhere..?? Thank you..!
November 2, 2010 at 7:29 am
November 2, 2010 at 7:35 am
Thanks so much...!! I deeply appreciate your help..!! Have a great day..!!
July 5, 2011 at 8:00 am
You can also try this GUI tool SQL Backup and FTP which lets you schedule your backups. It is very simple to use and it's free 🙂
January 17, 2013 at 7:42 am
January 18, 2013 at 6:55 am
Here is a simple example.
First file is the .sql script. It is invoked using SQLCMD in a batch file. Create one of these .sql files for each of the databases that you want to back up, including the system databases (master, model, msdb).
Then create a .bat file and have a line in it invoking SQLCMD for each of the database files that you want to run.
MyDatabase_backup_script.sql
==========================
DECLARE @fn nvarchar(256),
@dbname nvarchar(50),
@stmt nvarchar(4000),
@path nvarchar(4000)
SET @dbname = 'MyDatabase'
SET @path = 'c:\SQLBackups\' + @dbname + '\'
SET @fn = @path + @dbname + '_backup_' +
CONVERT(nchar(8),getdate(), 112) +
right(N'0' + rtrim(CONVERT
(nchar(2), datepart(hh, getdate()))), 2) +
right(N'0' + rtrim(CONVERT
(nchar(2), datepart(mi, getdate()))), 2) +
N'.bak'
--SELECT @fn
SET @stmt = 'BACKUP DATABASE '
+ QUOTENAME(@dbname, '[') + ' to disk
= ''' + @fn + ''''
--SELECT @stmt
EXEC (@stmt)
Database_backups.bat
==========================
sqlcmd -S (local)\SQLEXPRESS -E -i C:\SQLEE_Backups\MyDatabase_backup_script.sql -o C:\SQLBackupLogs\MyDatabase_backuplog.txt
Have one of these lines for each database to back up, then just schedule the .bat file to run every night, say at 1am.
The (local) part runs on the local machine, where the batch file is ran. This could be changed to the specific server or pc name if needed.
The -o text file is the output log file of the run. It will show any errors if it encounters any. I would keep the name in a format that will just overwrite itself so you don't have to worry about multiple versions to clean up. Note that this will be an issue with the database backups, since the script backs it up to a file name with a date stamp on it.
Here is an example of a .sql script to do a tranlog backup. Again, just have a .sql file for each database that you need to do tranlog backups for, and put them in a separate .bat file and set to run multiple times per day.
Tranlog backup script
==================================
DECLARE @fn nvarchar(256),
@dbname nvarchar(50),
@stmt nvarchar(4000),
@path nvarchar(4000)
SET @dbname = 'MyDatabase'
SET @path = 'c:\SQLBackups\' + @dbname + '\tlogs\'
SET @fn = @path + @dbname + '_backup_' +
CONVERT(nchar(8),getdate(), 112) +
right(N'0' + rtrim(CONVERT
(nchar(2), datepart(hh, getdate()))), 2) +
right(N'0' + rtrim(CONVERT
(nchar(2), datepart(mi, getdate()))), 2) +
N'.trn'
--SELECT @fn
SET @stmt = 'BACKUP LOG '
+ QUOTENAME(@dbname, '[') + ' to disk
= ''' + @fn + ''''
--SELECT @stmt
EXEC (@stmt)
Hope it helps.
February 2, 2013 at 10:42 am
vikingDBA (1/18/2013)
Create one of these .sql files for each of the databases that you want to back up, including the system databases (master, model, msdb).
Why is there need to backup system DBs too?
February 4, 2013 at 2:51 am
System databases can get corrupted just as user databases.
In case of corruption, you'll need a backup copy if you don't want to install from scratch.
-- Gianluca Sartori
February 4, 2013 at 9:02 am
Thank you. I assume the system db backup actions are less often then user dbs.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply