?
Solved

SQL Backup Scripts

Posted on 2013-10-23
2
Medium Priority
?
251 Views
Last Modified: 2013-10-23
I am going through all of our different sql servers and correcting some backup scripts that were failing. This is the script that I'm using as a single step in an SQL Agent Job:

DECLARE @FILENAME AS VARCHAR(255)
SELECT @FILENAME = N'D:\SQL Backups\AERT\AERT_Full_' + CAST(GETDATE() AS VARCHAR(20)) + '.bak'

BACKUP DATABASE [AERT] TO  DISK = @FILENAME WITH NOFORMAT, NOINIT,  NAME = N'AERT-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'AERT' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'AERT' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''AERT'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM  DISK = @FILENAME WITH  FILE = @backupSetId,  NOUNLOAD,  NOREWIND
GO

Open in new window

This code is failing with this error: Msg 137, Level 15, State 2, Line 4
Must declare the variable '@FILENAME'.

This particular script will hopefully be used on SQL Server 2000.
0
Comment
Question by:Carla Romere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
PadawanDBA earned 2000 total points
ID: 39595450
The GO command terminates the batch and the variable declaration/definition along with it.  Go ahead and try removing that.
0
 

Author Closing Comment

by:Carla Romere
ID: 39595632
This was perfect.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question