SQL Server 2005 Full Backup Script
Apr 4, 2007
We have a script that I had to rework a little bit for 2005 that does
a full backup for every database on the server... For some reason on
some nights the script does not backup all databases... Its like it
skips over it for some reason... Output of the script below on the
night in question was:
Executed as user: NT AUTHORITYSYSTEM. master [SQLSTATE 01000]
(Message 0) Status is ONLINE dbname / dbdevice = master / SQLBUmaster
[SQLSTATE 01000] (Message 0) Processed 376 pages for database
'master', file 'master' on file 1. [SQLSTATE 01000] (Message 4035)
Processed 2 pages for database 'master', file 'mastlog' on file 1.
[SQLSTATE 01000] (Message 4035) BACKUP DATABASE successfully
processed 378 pages in 0.169 seconds (18.298 MB/sec). [SQLSTATE 01000]
(Message 3014). The step succeeded.
A normal night on this particular server includes two other databases
like below:
(Message 0) Processed 376 pages for database 'master', file 'master'
on file 1. [SQLSTATE 01000] (Message 4035) Processed 2 pages for
database 'master', file 'mastlog' on file 1. [SQLSTATE 01000] (Message
4035) BACKUP DATABASE successfully processed 378 pages in 0.711
seconds (4.349 MB/sec). [SQLSTATE 01000] (Message 3014) msdb
[SQLSTATE 01000] (Message 0) Status is ONLINE dbname / dbdevice =
msdb / SQLBUmsdb [SQLSTATE 01000] (Message 0) Processed 688 pages for
database 'msdb', file 'MSDBData' on file 1. [SQLSTATE 01000] (Message
4035) Processed 5 pages for database 'msdb', file 'MSDBLog' on file
1. [SQLSTATE 01000] (Message 4035) BACKUP DATABASE successfully
processed 693 pages in 3.743 seconds (1.516 MB/sec). [SQLSTATE 01000]
(Message 3014) SBC [SQLSTATE 01000] (Message 0) Status is ONLINE
dbname / dbdevice = SBC / SQLBUSBC [SQLSTATE 01000] (Message 0)
Processed 11577184 pages for... The step succeeded.
The script is schedule to be run nightly and it looks like this:
ALTER PROCEDURE [dbo].[usp_backupFull] AS
set nocount on
Declare @start_time datetime,
@end_time datetime,
@backupsize real,
@status varchar(100),
@cmd nvarchar(255),
@monitor_server varchar(50),
@recovery varchar(100),
@db_name varchar(100),
@dev varchar(100),
@logvarchar(100),
@backup_folder varchar(100),
@dev_path varchar(255),
@log_pathvarchar(255),
@message_text varchar(255),
@subject_text varchar(255),
@error varchar(50)
Select @backup_folder ='D:SQLBU'
--Select @monitor_server ='MONITOR'
CREATE TABLE #error (dbname varchar(50), error varchar(50))
DECLARE db_cursor CURSOR FOR SELECT name FROM master..sysdatabases
where name not in ('Northwind','pubs','tempdb','model')
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @db_name
WHILE @@FETCH_STATUS = 0 BEGIN
SELECT @dev = 'SQLBU' + @db_name
SELECT @dev_path = @backup_folder + @dev + '.bak'
SELECT @log = 'SQLBU' + @db_name + 'LOG'
SELECT @log_path = @backup_folder + @dev + '_log.bak'
PRINT ''
PRINT @db_name
PRINT ''
IF NOT EXISTS (SELECT name FROM master..sysdevices where status=16
and name=@dev) BEGIN
-- Create new backup device if it doesn't exist
EXEC sp_addumpdevice
@devtype='Disk',@logicalname=@dev,@physicalname=@d ev_path
PRINT ''
END
Select @recovery =
CONVERT(varchar(100),DATABASEPROPERTYEX(@db_name,' Recovery'))
IF @recovery <'SIMPLE' BEGIN
IF NOT EXISTS (SELECT name FROM master..sysdevices where status=16
and name=@log) BEGIN
-- Create log backup device if it doesn't exist and logging not set
to SIMPLE
EXEC sp_addumpdevice
@devtype='Disk',@logicalname=@log,@physicalname=@l og_path
END
END
SELECT @status = CONVERT(VARCHAR(100),DATABASEPROPERTYEX(@db_name,
'Status'))
print 'Status is ' + @status + ' dbname / dbdevice = ' + @db_name +
' / ' + @dev
IF @status = 'ONLINE' BEGIN
SELECT @cmd = 'BACKUP DATABASE ' + @db_name + ' TO ' + @dev + ' WITH
INIT'
EXEC(@cmd)
IF @@ERROR <0 BEGIN
INSERT INTO #error VALUES (@db_name,'Full backup Failed-Check Log')
--Select @cmd = 'osql -U srvMonitor -P backups -S ' +
@monitor_server + ' -d Monitor -Q "insert into backups
([date],server_name,db_name,backup_type,status) values (GETDATE(),'''+
@@servername +''',''' + @db_name + ''',''Full'',''Failed'')"'
--Execute master..xp_cmdshell @cmd
END
ELSE BEGIN
SELECT @start_time = backup_start_date, @end_time =
backup_finish_date, @backupsize = (backup_size / 1024 / 1024) FROM
msdb..backupset WHERE (type = 'd') AND (database_name = @db_name) AND
(backup_finish_date DATEADD(mi, -1, GETDATE()))
--Select @cmd = 'osql -U srvMonitor -P backups -S ' +
@monitor_server + ' -d Monitor -Q "insert into backups values
(GETDATE(),'''+ @@servername +''',''' + @db_name +
''',''Full'',''Success'',''' + cast(@start_time as varchar(50)) +
''',''' + cast(@end_time as varchar(50)) + ''',' + cast(@backupsize as
varchar(50)) + ')"'
--Execute master..xp_cmdshell @cmd
END
PRINT ''
SELECT @recovery =
CONVERT(VARCHAR(100),DATABASEPROPERTY(@db_name,'Is TruncLog'))
IF @recovery <'1' BEGIN
SELECT @cmd='BACKUP LOG '+@db_name+' TO ' + @log + ' WITH INIT'
EXEC(@cmd)
IF @@ERROR<>0 BEGIN
INSERT INTO #error VALUES (@db_name,'Log backup Failed-Check Log')
--Select @cmd = 'osql -U srvMonitor -P backups -S ' +
@monitor_server + ' -d Monitor -Q "insert into
backups([date],server_name,db_name,backup_type,status) values
(GETDATE(),'''+ @@servername +''',''' + @db_name +
''',''Log'',''Failed'')"'
--Execute master..xp_cmdshell @cmd
END
ELSE BEGIN
SELECT @start_time = backup_start_date,@end_time=
backup_finish_date, @backupsize = (backup_size / 1024 / 1024) FROM
msdb..backupset WHERE (type = 'L') AND (database_name = @db_name) AND
(backup_finish_date DATEADD(mi, -1, GETDATE()))
--SELECT @cmd = 'osql -U srvMonitor -P backups -S ' +
@monitor_server + ' -d Monitor -Q "insert into backups values
(GETDATE(),'''+ @@servername +''',''' + @db_name +
''',''Log'',''Success'',''' + cast(@start_time as varchar(50)) +
''',''' + cast(@end_time as varchar(50)) + ''',' + cast(@backupsize as
varchar(50)) + ')"'
--Execute master..xp_cmdshell @cmd
END
END
PRINT ''
END
ELSE BEGIN
PRINT 'The database was not backed up due to options that were set
under sp_dboptions'
PRINT ''
INSERT INTO #error VALUES (@db_name,'DB Not backed up due to DB
options')
--Select @cmd = 'osql -U srvMonitor -P backups -S ' +
@monitor_server + ' -d Monitor -Q "insert into backups
([date],server_name,db_name,backup_type,status) values (GETDATE(),'''+
@@servername +''',''' + @db_name + ''',''Full'',''Not Backed up -
Check DB Options'')"'
--Execute master..xp_cmdshell @cmd
END
FETCH NEXT FROM db_cursor into @db_name
END--WHILE
-- Open error cursor --
DECLARE db_error CURSOR FOR SELECT dbname,error from #error
OPEN db_error
FETCH NEXT FROM db_error into @db_name,@error
WHILE @@FETCH_STATUS = 0 BEGIN
SELECT @message_text = @error + ' for ' + @db_name
SELECT @subject_text = '!!!!!! ' + @@servername + ' - Backup
failed for ' + @db_name + ' !!!!!!'
--exec msdb..usp_Alerts @mess = @message_text ,
@subj=@subject_text
FETCH NEXT FROM db_error into @db_name,@error
END --WHILE
DROP TABLE #error
PRINT ''
DEALLOCATE db_cursor
DEALLOCATE db_error
set nocount off
---------------------------------------------------------------
Any help I would appreciate it... As you can see from the output above
it looks like its not even getting the database name to backup in the
cursor. But that just doesn't make any sense to me... why could that
be.
View 2 Replies
ADVERTISEMENT
Jun 29, 2007
Hi,
After some advice - I have a SQL Server 2005 database which is part
of an anti-virus setup. The main database is 25Gb is size, and it
is running in simple recovery mode. There are two backup jobs in
place, one to do a differential backup each Mon-Sat, and one to
do a full backup on Sun. Although the backups do get done they
are taking 5 hours to do. Any wiz out there care to suggest what
the problem is, I would've though that maybe an hour was more
acceptable ?
Cheers,
Gordon
View 2 Replies
View Related
Aug 3, 2015
Need to restore database,here's the scenario:
Data got deleted on Friday evening, need to have database restored to FRiday afternoon and also some data has been entered on Monday, which needs to be there.
View 8 Replies
View Related
Jul 20, 2005
If a full backup kicks off at 6pm within SQL Server, and takes 2 hoursto complete, will transactions between 6pm and 8pm be included in thebackup?Tks
View 1 Replies
View Related
Sep 11, 2007
I want to set a full and differential backup to one database in sql server 2000.
Is there a way to set both full and differential to just one database.
i want the full backup weekly once and differential every day to set up.
Please let me know
View 3 Replies
View Related
Oct 27, 2015
I've got the below and have several variation and still cant seem to find a perfect way to query the server to bring back that last full backup per db. I'm shopwing mutilple records in the backup set db w/ type = 'D'. I look online and type D = Database. Which i assumed it meant full database backup. Apparently not. Try running the below on one of your full databases. Then check to see if the date is actually the last backup date.
DECLARE @db_name VARCHAR(100)
SELECT @db_name = DB_NAME()
-- Get Backup History for required database
SELECT TOP ( 30 ) s.database_name,
m.physical_device_name,
[Code] ....
View 9 Replies
View Related
Mar 25, 2008
Hi,
Is there any option to restore a specific object from a full database backup file?
View 3 Replies
View Related
Feb 19, 2015
Using Ola Hallengren's scripts I do a full backup of a database on a Sunday. Then differential backups every 6 hours and log backups every hour. I would like to keep a full week of backups based off the full backup done on Sunday. Is there a way for me to clear out the diff and log folders after the successful full backup on Sunday nights?
View 2 Replies
View Related
Jul 15, 2015
We take a full backup in the early morning and hourly transaction log back during the working hours for one database in the production server. The application team made certain changes to the design of the said database in their development server. The backup from the development server was restored to the production server during working hours. After the restoration should we take a full backup before next transactional logbackup? Would the transactional log backup with out a full backup after the restoration of a database be valid?
View 5 Replies
View Related
Nov 16, 2015
I have a database that is just over 1.5GB and the Full backup that is 13GB not sure how this is since we have compression on for full backups and my other full backups are much smaller than there respective databases...Now my full backup is taken every Sunday night and the differentials are taken every 6 hours after the full backup. Now I have been thrown into this DBA role with little to no experience just what I have picked up and read. So my understanding of backups are limited but what I think I understand is that we take a full backup and the differential only captures what changes in the database so my question is why is my database 1.5GB but my differential is 15.4GB? I have others database that are on the same instance and don't seem to have this problem. I also just noticed that we do not rebuild the index before a full backup like we do on other instances...
View 13 Replies
View Related
Nov 12, 2014
Recently I have faced one DBA interview, below is the question they asked me.
" Does AlwaysON secondary replica support Full backup, if it is not why"?
I know AlwaysON secondary replicas support only copy_only and tlog backups, why they wont support full backup?
View 9 Replies
View Related
Nov 13, 2014
If data is modified (by an insert, update, or delete) while the backup is running, will the backup contain those changes or will it be added to the database afterwards?
View 2 Replies
View Related
Jan 29, 2007
Hello all - I have a SQL Server 2000 database setup using the Full Recovery Model. Each night, we backup the entire database, and as such would like to truncate the log at this time as well.
Is the best way to do this to also backup the Transaction Log, and then perform a DBCC SHRINKFILE command? It just seems like there should be an easier way...?
Thanks!
View 1 Replies
View Related
Nov 29, 2007
If my backup starts at 8PM and take 1 hour to complete, will the changes made to the database during that hour be captured in the full backup?
Stated another way, will my backup be a snapshot of:
a) 8PM when the backup started
b) 8PM with some of the changes made between the hour
c) 9PM when the backup finished?
Anybody know the exact way SQL Server handles that logic?
Thanks,
Marc
View 2 Replies
View Related
Jul 19, 2007
Hi
I am using the Simple recovery model and I'm taking a weekly full backup each Monday morning with differentials taken every 4 hours during the day.
On Wednesday afternoon, a programmer ran a process that corrupted the db and I had to restore to the most recent differential. It was 5pm in the afternoon and a differential backup had just occured at 4pm. No problem, I figured.
I restored the full backup from Monday morning and tried to restore the most recent differential backup. The differential restore failed. Since I had used T-SQL for the initial attempt, I tried using Enterprise Manager to try again.
When viewing the backup history, I see my initial full backup taken on Monday plus all the differentials. BUT, on closer inspection, I noticed another full backup in the backup history that was taken early Tuesday morning. I can't figure out where this Tuesday morning full backup came from. It wasn't taken by me (or scheduled by me) and I'm the only one with access to the server. My full backups are usually named something like HCMPRP_20070718_FULL.bak. This erroneous full backup was named something like HCMPRP_03a_361adk2k_dd53.bak. It seemed like it was a system generated name. Not something I would choose. To top it off, I could not find this backup file anywhere on the server and when I tried to restore using this full backup, it failed.
Does anyone have any clues as to where this full backup might come from? Does SQL Server trigger a full backup on its own if some threshold is reached?
I ended up having to restore using the differential taken just before this erroneous full backup and lost a day of transactions.
Any insight is greatly appreciated.
View 3 Replies
View Related
Aug 8, 2007
Hello,
I have MS SQL 2005 server with 300+ databases on it. The application is set up that way that it creates a new database as needed (dynamically). Do not ask me why - I hate this design... So, it can create 3-4 databases a day (random time).
I've scheduled full backup of all databases to run once at night, and it runs just fine. Besides that, I have scheduled tran logs backup of all databases to run every hour. This backup fails from time to time with the following error:
Executing the query "BACKUP LOG [survey_p0886464_test] TO DISK = N'D:\backups\log backups\survey_p0886464_test_backup_200708072300.trn' WITH NOFORMAT, NOINIT, NAME = N'survey_p0886464_test_backup_20070807230002', SKIP, REWIND, NOUNLOAD, STATS = 10
" failed with the following error: "BACKUP LOG cannot be performed because there is no current database backup.
BACKUP LOG is terminating abnormally.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
So, I think what happens is since my full backup of all databases are scheduled to run only once at night, and tran logs every hour, when new database is created during the day, there is no full backup for it, that is why tran logs backup fails. Becuase after the failure, if I run full backup again, then tran log runs just fine afterwards.
I am new to MS SQL Server, I am mostly working with Sybase IQ. Do you know if I can "trigger" full backup every time when new database created to avoid tran lof failure?
Or is it possible to schedule full backup to run if tran log backup fails?
Any advice will be much appreciated.
View 1 Replies
View Related
Oct 17, 2006
I have a full backup and several diff backup,now i want to restore
firstly,I restore full backup
RESTORE DATABASE ***
FROM DISK = 'D:databackup200610140000.bak'
WITH NORECOVERY
GO
it's working,then i don;'t know how to continue
Thanks in advance
View 3 Replies
View Related
Apr 4, 2015
I am working towards automating the process of testing our backups. For the meantime, I do it all manually - I copy the backup files (full + transaction logs) to our test server and then run the restore script. Once database restored I run the DBCC CheckDB. The results of checkdb I manually upload to our Sharepoint portal as proof that the backup file is intact with no errors.
here are some ideas I have but have not yet tested:
Create a maintenance plan with each 3 jobs:
--> Powershell script to copy the files from Prod server to Test server - add this scrip to Job1
--> Powershell script to restore databases files - add this script to Job2
--> Run the DBCC in powershell (yet to find if possible in PS) - add this script to Job3
I would like to use seperate jobs as to get a report on the duration and status of each job
Would also like to get the results of the DBCC Checkdb as proof that no errors were found for upload to our Sharepoint portal. Dont know if possible via the job.
View 8 Replies
View Related
Mar 11, 2008
Hello, everyone:
I just heard that for restore purpose, ths full backup and transaction log backup should be from one maintenance plan. Otherwise transaction log backup files cannot be restored after restoring full backup files.
Is it true? Can anyone offer official documents?
In my system, full and transaction backups are from one maintenance plan. Restores are doing fine. I am not sure that ideal is true or not.
Thanks
ZYT
View 2 Replies
View Related
Mar 15, 2007
If I create an adhoc db backup that takes, say 30 miuntes to complete, should I suspend the tran log backups that run every 10 minutes, until the full backup is complete?
Drew
View 9 Replies
View Related
Jun 6, 2007
Hi,
Using SQL Server 2005, we have a 2.8Gb database under the Simple recovery model. The database contains ~50M rows and each night ~60k rows are loaded(appended) to the database by a SSIS task.
We configured a Maintenance Plan which is executed once a week to perform a full backup of the database. The resulting backup file is ~2.8Gb, as expected.
We also configured another Maintenance Plan which is executed every day, a few hours after the SSIS task is executed, to perform a differential backup. To our surprise, the resulting backup file is about the same size as the full backup, ~2.8Gb when it should only be a few MB (only 60k rows are added to the database)
When we launch the "Restore Database" wizzard we clearly see the different backup set, Full and Differential but they all have about the same size (same for the physical backup file on disk).
Is there anything we are missing, why are the differential backup that big?
Thanks for any advice.
View 4 Replies
View Related
Apr 15, 2008
I have only one tape drive.
My server is using the SQL server 2005 backup tool and arcserve backup tool to backup different files .
Everytime I need to disable and enable the tape device driver (in device manager /windows) before I can use SQL server 2005 backup tool.
Everytime I need to disable and enable the tape device driver (in device manager /windows) before I can use arcserve backup tool.
It seems that the tape device resource is held by softwares even the tape drive is not in use.
What should I do to make the tape drive shared by different softwares?
Regards,
Manuel
View 2 Replies
View Related
Apr 12, 2007
Hi,
I have an ASPNETDB.MDF (asp.net membership/profile db) that was generated for SQL Express, it has user information I need to keep.
I have SQLExpress and full SQL Server 2005 running on the server. I want to remove SQL Express from the server.
So can I simply do a backup of the SQL Express membership db and restore it to full SQL and change the connection string in my app or
do i need to run the membership wizard on full sql and then do the backup / restore?
Or is there another way.
Thanks
View 1 Replies
View Related
Oct 23, 2015
In SQL Server, whether the full backup of a database includes the backup of the log?
View 1 Replies
View Related
Jun 14, 2007
Hi:
I have 30 databases on sql server 2005 that I need to do a full backup every morning at 7:00 and tran log backup every 30 minutes until 7:00 PM. If I create a maintenance plan for a backup using the wizard I have the option of starting a full backup at 7 am and then an option of doing tran log backups every hour using a different schedule. I plan on selecting the option to create a different folder for every database. I just need to confirm that in this way the way to restore the data would be
1. to restore a full backup
2. apply all the tran logs depending on the time they want to recover back to.
I just think this is the easiest approach to have 30 databases on the same backup scheme instead of creating a separate backup device for each database and doing a full backup on that device and appending all tran logs to that device which means just 1 bak file versus the above strategy with a number of tran log files. Please advise.
Thanks
View 1 Replies
View Related
Feb 25, 2008
I have a basic question to ask:
I have two server both showing SQL server 2005 installed. One of them is a licensed SQL server 2005 and the other is a express edition.
I am trying to find out which one in is express and which is the full licensed version.
I checked at the control pane and they both show up as SQL server 2005. The directory structure at Program Files looks the same.
Please help me.
Thanks,
Karthik
View 1 Replies
View Related
Jan 28, 2008
I have this simple full text search query that works perfectly on my own computer using sql server 2005 express, however, on the production server(shared hosting)when I added the first 50+ rows, the full text search works perfect, but as the number of rows increases, the full text search can only see the first50+ rows, but not the new ones. Is there any quick solution for this or it's just a common mistake for developers for not properly indexed columns?Is there a way to re-indexed all rows without loosing data on the live server? search query: SELECT TOP 50 *FROM li_BookmarksWHERE FREETEXT(Keywords,@Keywords)
View 2 Replies
View Related
Jan 5, 2008
in object explorer ,do right-click on database and is selecting preoperties and is selecting "files" page "use full-text indexing" ckeck box is disable.
how can enabled this check box?
thanks , mohsen
View 1 Replies
View Related
Apr 8, 2007
Hi,
I am putting this question here but I am not limiting it to sql server 2005 express edition.
I am developing an app on a local machine (winxp with sql server 2000 personal edition) however I came to find out that full-text does not work in this setup unless I use a server type machine.
This fouls up my development somewhat and I would like to know if there is
a) a work around for my sql server 200 setup
b) does full-text serach work in sql server 2005 express edition which I have installed on my PC ?
Thanks for any input on this issue.
Tuka
View 2 Replies
View Related
Jul 20, 2005
I start a full backup on a database at 5pm. The backup job takes 3hours to complete. While the backup job is running, someone insertsrecords to the db. Will the backup include the new records? Or inother words, are the contents of a SQL Server backup a snapshot of thedatabase at the start time of the backup?
View 1 Replies
View Related
Feb 8, 2007
I installed SQL Server 2005 express with advanced services which is supposed to include full-text search capability but I can't get it to work. When I try to create a full-text catalog it gives me an error because it does not think the full-text service is installed or loaded. I can't seem to find a reference to the full-text search feature to enable or install it. any ideas?
View 3 Replies
View Related
Feb 5, 2008
the sql server documentation states that the use of wildcards is allowed by placing an '*' at the end of the search term. I can get this to work OK in the SQL Server 2005 query window, heres an example
select ID, SUBSTRING(Title, 1, 100) AS Title, Implemented, Published from Table1 where contains(title,'"Therap*"') ORDER BY Title
this works OK and returns a list ot titles with the word Therapy in the title
Im trying to implelemnt this functionalty in a web app with C#. The string is passed to a stored procedure. How on earth do I pass in the quotes ??
Ive tried building the string as normal then adding single quotes on the end, so I get something like
retval = txt + "*"; //txt contains the partial word im searching for, then add the wildcard
then retval = "'" + retval + "'"; // add the single quotes
and pass txt as a string parameter to my stored procedure. It doesnt work. Can anyone tell me what im doing wrong ??
the same query works fine in the SQL query window.
View 7 Replies
View Related
Jan 9, 2006
Lets say I use the 'enabling roles' for my ASP 2.0 site. This creates a ASPNETDB.DBF SQL Express file.
Later I go to post this to a real web server - which runs the 'full' MS SQL2005 server. What happens to the ASPNETDB.MDF file (or for that matter, any other MDF file I create with SQL Express) when it leaves the Express world and enters the Real world.
View 4 Replies
View Related