Showing posts with label express. Show all posts
Showing posts with label express. Show all posts

Wednesday, March 28, 2012

scheduling maintenance activities

Am I able to do this in SS Express -like a backup or something or do I need to purhcase a SQL Server Agent (I believe I saw a 3rd party company always advertising this in SQL Server Central.com). It's cheap -- just curious if I really need it.

SQL Express does not contain any specific scheduling tools. You can schedule T-SQL scripts to be run using Windows Task Scheduler and SQLCmd, which is a free solution as Task Scheduler is part of Windows.

For more complex needs, a third party scheduling tool is an option.

Regards,

Mike Wachal
SQL Express team

-
Mark the best posts as Answers!

sql

Scheduling jobs

It appears that SQL 2005 Express has removed the SQL Agent. Is this true?
Or, am I simply missing something obvious? If not there, does anyone know
the minimum version of SQL 2005 which enables job scheduling?
Thank in advance,
Gary Johnson
Hello,
Yes it is. SQL Express do not have SQL Agent. You could use Windows
schedular to schedule the tasks like Backup, Monitoring, Procedure execution
ect...
See the info from Microsoft URL:-
SQL Agent
SQL Agent is a SQL Server service that is used to automatically schedule job
execution for SQL Server. It is typically used to schedule the execution of
DTS packages or to perform system maintenance tasks like database backups.
While MSDE includes the SQL Agent service, SQL Server 2005 Express does not.
However, you can use the Windows built-in Task Scheduler to schedule jobs
for SQL Server 2005 Express. You can use Task Scheduler in combination with
the downloadable DTS runtime to automatically schedule the execution of DTS
packages. Likewise, you can use Task Scheduler in combination with the SQL
Server 2005 Express command-line SQLCMD tool to regularly execute SQL Server
2005 Express system maintenance jobs like database backups and other
database access jobs.
http://www.microsoft.com/technet/prodtechnol/sql/2005/msde2sqlexpress.mspx
Thanks
Hari
"Gary Johnson" <gary.johnson@.geoffreynyc.com> wrote in message
news:b9401$45baae1c$44a72b52$14138@.msgid.meganewss ervers.com...
> It appears that SQL 2005 Express has removed the SQL Agent. Is this true?
> Or, am I simply missing something obvious? If not there, does anyone know
> the minimum version of SQL 2005 which enables job scheduling?
> Thank in advance,
> Gary Johnson
>
|||Service Broker also works well as a job scheduler and is available in SQL
Express:
http://blogs.msdn.com/rogerwolterblog/archive/2006/04/13/575974.aspx
http://www.microsoft.com/technet/technetmag/issues/2005/05/ServiceBroker/default.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Gary Johnson" <gary.johnson@.geoffreynyc.com> wrote in message
news:b9401$45baae1c$44a72b52$14138@.msgid.meganewss ervers.com...
> It appears that SQL 2005 Express has removed the SQL Agent. Is this true?
> Or, am I simply missing something obvious? If not there, does anyone know
> the minimum version of SQL 2005 which enables job scheduling?
> Thank in advance,
> Gary Johnson
>
sql

Monday, March 26, 2012

Scheduling an automatic backup

I have only started using SQL Server 2005 Express Edition recently.I also installed Management Studio Express version to manage the database. While testing the database I had came across some question and they are:
    Can I upgrade from SQL Server 2005 Express to Workgroup/Standard/Enterprise without loosing the database and its contents. While I backed up the database, I was permitted to backup only on to my local drive even though I have administrative rights on the system. It would be easy if I could backup to a network drive directly.My question is:Is it possible to backup directly to a network drive rather than backing the database to a local drive and then "copy and paste" it to a network drive.
    Windows Scheduler: I have scheduled a daily backup of the database by midnight. I have also written the script to run the backup. But every time the scheduler starts the backup, it asks for the database password. This halts the backup until I come back in the morning and manually enter the password. My question is: is it possible to run an automatic database backup using Windows Scheduler? I understand that there are 2 types of backups: full and differential backups. My question is: Is it possible to dynamically allocate different names automatically to consecutive backups so that the previous backups are not over written

Thanks for your patience and time.

regards,
Berly Sam

1. Yes

2. SQL Server only allows backups to local drives or LUNs. There are third party backup tools that will backup to a network drive/share. I usually have a job step that 'moves' the files to a network share after the backup is complete.

3.Yes. I assume that you are using SQLCmd.exe. Use on of the following command line arguements (switches): -U login_id [ -P password ] } OR –E trusted connection. For addtional information, see Books Online, Topic: "SQLCmd Utility'. If necessary, you can download a copy of Books Online here.

4. Since you would need two separate Jobs scheduled, one for FULL backup and one for DIFFERENTIAL, then it seems that you would not have any issue having two different names. And yes, you can dynamically create your file names.

|||Thank you Mr. Rowland for replying.
But in the question of Back ups: i need to create different differential backups which take different names dynamically. Is it possible to schedule differential backups without over writing the previous backup.

Thank you for your time and patience
Regards
Berly Sam
|||

They will not 'take' names.

You will have to dynamically, and in your script/code, create the names and provide them to the backup command.

|||I was working over the backup case but was unable to come up with a solution as to how i can automatically backup the database while dynamically allocating names to consecutive differential backups. Just a reminder, the database I am using is SQL Server 2005 Express edition.

The script that is used to run the backup is
BACKUP DATABASE [DatabaseName] TO DISK = N'C:\BackUp\ST_BKUP_14_06_07'WITH DIFFERENTIAL , NOFORMAT, NOINIT, NAME = N'DatabaseName-Differential Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO

I have also run the SQLCMD utility.
C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE -S [SERVER] -U backupadmin -P [PASSWORD] -i B:\ST_BACKUP\sqlscript.sql

What else must i do so that i get an automatic backup without being asked to login for every scheduled backup.Since the 'login' makes it compulsory for me to be on the system while the backup takes place. Is there any alteration i must make so that different names are alloted to consecutive backups thus not overwriting an old backup.|||

Before the part of the script that executes the BACKUP command, create a variable with the name you wish to use.

Code Snippet


DECLARE @.MyBackupName nvarchar(250)


SET @.MyBackupName = 'C:\BackUp\ST_BKUP_' + convert( varchar(10), getdate(), 112 ) + '.BAK'

BACKUP DATABASE [DatabaseName] TO DISK = @.MyBackupName
WITH DIFFERENTIAL ,
NOFORMAT,
NOINIT,
NAME = N'DatabaseName-Differential Database Backup',
SKIP,
NOREWIND,
NOUNLOAD,
STATS = 10

Every time this runs, the file name will be in the form: ST_BKUP_20070614.BAK, with the date changing every day.

|||

Very cool.

So, for addition information I have a question:

1-Can I create a Stored Procedure with this code and then run it from a command line (cmd) ?

2-Can I to use the osql.exe to run this command or run the Stored Procedure created with this code ?

Tks,

Mura

|||

1. By using OSQL or SQLCmd.

2. Yes, OSQL.exe with SQL 2000, SQLCmd.exe with SQL 2005.

You can use the Windows Scheduler service to automate this.

|||Thank you Mr. Rowland for replying.
Your posts have helped me solve my problem of dynamic name allocation to my backups.
Although I could solve that, the scheduled backup does not execute at the specified time and will be halted till I manually enter the login information. My question is how can i remove the login option that i have to fill-in every time a scheduled backup script is run.

This would complete my question of how an automatic backup is done in SQL Server.
Thank you for your time and patience

Regards
Berly Sam
|||

This command line prompts the user for a Server and password.

C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE -S [SERVER] -U backupadmin -P [PASSWORD] -i B:\ST_BACKUP\sqlscript.sql

I suggest that you put in the ServerName in place of [SERVER], and that you use -E instead of: -U backupadmin -P [PASSWORD]. So my suggested command line would be:

C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE -S MyServerName -E -i B:\ST_BACKUP\sqlscript.sql

|||Tkx guy,|||Thank you Mr. Rowland,
I could solve my problem. I really appreciate the time and energy you invested to help me with my issue.Once again thank you
Regards
Berly Sam
|||When I executed this code, it works fine, but the thing is when I tried to change the style in the convert function its throwing an error. The dynamic file which which is generated for each backup should have the date and also the time for me . Can anyone help me on this.
|||

You have probably selected a time format that contains characters unacceptable in a path/filename.

You may prefer to do something more like this:


Code Snippet


DECLARE @.MyBackupName nvarchar(250)


SET @.MyBackupName = 'C:\BackUp\ST_BKUP_'
SET @.MyBackupName = @.MyBackupName + convert( varchar(10), getdate(), 112 ) + '_'
SET @.MyBackupName = @.MyBackupName + replace( convert( varchar(5), getdate(), 108 ), ':', '' )
SET @.MyBackupName = @.MyBackupName + '.BAK'


SELECT @.MyBackupName

--
C:\BackUp\ST_BKUP_20070618_2124.BAK

Friday, March 23, 2012

Scheduling a backup on SQL Server Express

Hi,
is there a way to schedule a backup ?
Using the Management Studio Express I've seen only the way to Backup a
database but not to "schedule" a backup.
Any help or suggestion is appreciated
Adriano
hi Adriano,
Adry wrote:
> Hi,
> is there a way to schedule a backup ?
> Using the Management Studio Express I've seen only the way to Backup a
> database but not to "schedule" a backup.
>
unfortunately, SQLExpress does not provide the SQL Server Agent, so you have
to rely on os scheduled (AT, SCHTASKS) scripts to be run via osql.exe or
sqlcmd.exe...
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.15.0 - DbaMgr ver 0.60.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply

Scheduled tasks

Is it possible to schedule tasks in SQL Express, for example a database backup, or to periodically execute a stored procedure?

hi Allan,

yes, it is possible, but not using the SQL Server Agent as SQLExpress does not provide the relative bits.. you have so to rely on the native OS scheduler, third party (or self written alternative) scheduler, or rely on the Service Broker features..

personally I usually go for the native OS scheduler, where you can define a list of xx.sql scripts to be executed by a xx.cmd file.. then the xx.cmd file, connecting to SqlCMD.exe and executing each defined xx.sql script, has to be scheduled... quiete simple and not expensive... results are output to a text file similar to:

[cmdfile.cmd]

ECHO. >>Backing up databases

SqlCmd -E -S(Local)\InstanceName -i"c:\somefolder\ScheduledBackup.sql" >c:\SomeFolder\ScheduledBackupLog.txt

ECHO. >>Sending results via mail to aministrators

SqlCmd-E -S(Local) -Q"SET NOCOUNT ON; SELECT 'Mailing log of - ' + CONVERT(varchar, GETDATE());" >E:\e-VbHot\Files\Log\MailingLogBCKschedulato.txt
SqlCmd -E -S(Local)\InstanceName -Q"SET NOCOUNT ON; DECLARE @.ret int;EXEC @.ret = [applicationDB].[dbo].[amSMTPmail] @.Server = N'smtp server name', @.Sender = N'scheduledbackup@.my_company.com', @.AddressesTO = N'admin_name@.my_company.com', @.AddressesCC = N'me@.me.com', @.AddressesCCN = NULL, @.AttachFiles = N'c:\SomeFolder\ScheduledBackupLog.txt', @.Subject = N'Backup performed', @.MessageBody = N'Backup performed', @.UserName = NULL, @.UserPassword = NULL; SELECT @.ret AS [Execution result];" >>c:\SomeFolder\MailingLog.txt

[/cmdfile.cmd]

as you can see, I do personally even send the c:\SomeFolder\ScheduledBackupLog.txt resulting file via e-mail to a "list" of addresses.. this is performed via a (free) CLR stored procedure of mine, amDBObj, where the .Net code implements a poor's man SMTP mail feature to "replace" (ok... it is not comparable with) Database Mail missing feature of SQLExpress..

regards

|||

Thanks for the info Andrea. I will look into it.

Thanks, too, for the offer of the CLR email proc - but I already did one myself :)

sql

Tuesday, March 20, 2012

Scheduled Jobs

Its not possible to schedule jobs via Express is it? Like I have a process that connects to an Oracle system grabs the data... plays with it some and then inserts it into the MSSQL 2005 server... We need this process to run say every 2 hours... Express cant do that cant it?SQL Express has no SQL Agent job scheduling service. You can execute the appropiate jobs using SQLCMD and the AT or any other scheduling service on your machine.

See the feature comparison here: http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

hi,

in addition to Jens answer, you can perhaps have a look at "third party" solutions, both commercial and free, like http://www.valesoftware.com/products-express-agent.php and http://www.codeproject.com/useritems/SQLAgent.asp to implement scheduled features..

regards

|||another possible solution (thats free) is to create a small batch script that calls sqlcmd and does your sql processing. this batch file could then be scheduled using windows scheduling to be called every 2 hours.

Friday, March 9, 2012

Scheduled backup in SQL Server 2005 Express

SQL Server 2005 Express does not have any possibilities to schedule backup so
I have made a simple application for scheduling backup, running a stored
procedure in my database.
The procedure backup up to the same backup device so all backup sets are
stored in the same file. RETAINDAYS is set to 365.
In the “Restore Database” dialog in SQL Server 2005 Management Studio
Express I can se all backup sets in the backup file and also the ‘Expiration’
date for each backup set.
I thought that setting option INIT and NOSKIP would overwrite expired backup
sets but instead I get an error message “the medium on device <device>
expires on <date> and cannot be overwritten.
I though that new backup sets would be appended until a backup set expires
but it does not look like that.
Any suggestion on how to preserve backup sets for some days and then
overwrite it?
Help is appreciated.
Regards Kjell Arne Johansen
Hi
What I would do If I were you :-))))) just create .BAK file with GEDDATE()
contacinated , so later on you can delete those files based on file name.
"Kjell Arne Johansen" <KjellArneJohansen@.discussions.microsoft.com> wrote in
message news:6594778E-E17A-4304-AFB1-DFF2D0C8BFD6@.microsoft.com...
> SQL Server 2005 Express does not have any possibilities to schedule backup
> so
> I have made a simple application for scheduling backup, running a stored
> procedure in my database.
> The procedure backup up to the same backup device so all backup sets are
> stored in the same file. RETAINDAYS is set to 365.
> In the Restore Database dialog in SQL Server 2005 Management Studio
> Express I can se all backup sets in the backup file and also the
> Expiration
> date for each backup set.
> I thought that setting option INIT and NOSKIP would overwrite expired
> backup
> sets but instead I get an error message the medium on device <device>
> expires on <date> and cannot be overwritten.
> I though that new backup sets would be appended until a backup set expires
> but it does not look like that.
> Any suggestion on how to preserve backup sets for some days and then
> overwrite it?
> Help is appreciated.
> Regards Kjell Arne Johansen
>
|||Hi
Yes I have an option to create backup with unique filenames also but I want
to know if there is anything I can use in SQL Server to do this for me and if
INIT and NOSKIP or other options can be used.
Kjell Arne
"Uri Dimant" wrote:

> Hi
> What I would do If I were you :-))))) just create .BAK file with GEDDATE()
> contacinated , so later on you can delete those files based on file name.
>
>
> "Kjell Arne Johansen" <KjellArneJohansen@.discussions.microsoft.com> wrote in
> message news:6594778E-E17A-4304-AFB1-DFF2D0C8BFD6@.microsoft.com...
>
>

Scheduled backup in SQL Server 2005 Express

SQL Server 2005 Express does not have any possibilities to schedule backup s
o
I have made a simple application for scheduling backup, running a stored
procedure in my database.
The procedure backup up to the same backup device so all backup sets are
stored in the same file. RETAINDAYS is set to 365.
In the “Restore Database” dialog in SQL Server 2005 Management Studio
Express I can se all backup sets in the backup file and also the ‘Expirati
on’
date for each backup set.
I thought that setting option INIT and NOSKIP would overwrite expired backup
sets but instead I get an error message “the medium on device <device>
expires on <date> and cannot be overwritten.
I though that new backup sets would be appended until a backup set expires
but it does not look like that.
Any suggestion on how to preserve backup sets for some days and then
overwrite it?
Help is appreciated.
Regards Kjell Arne JohansenHi
What I would do If I were you :-))))) just create .BAK file with GEDDATE()
contacinated , so later on you can delete those files based on file name.
"Kjell Arne Johansen" <KjellArneJohansen@.discussions.microsoft.com> wrote in
message news:6594778E-E17A-4304-AFB1-DFF2D0C8BFD6@.microsoft.com...
> SQL Server 2005 Express does not have any possibilities to schedule backup
> so
> I have made a simple application for scheduling backup, running a stored
> procedure in my database.
> The procedure backup up to the same backup device so all backup sets are
> stored in the same file. RETAINDAYS is set to 365.
> In the Restore Database dialog in SQL Server 2005 Management Studio
> Express I can se all backup sets in the backup file and also the
> Expiration
> date for each backup set.
> I thought that setting option INIT and NOSKIP would overwrite expired
> backup
> sets but instead I get an error message the medium on device <device>
> expires on <date> and cannot be overwritten.
> I though that new backup sets would be appended until a backup set expires
> but it does not look like that.
> Any suggestion on how to preserve backup sets for some days and then
> overwrite it?
> Help is appreciated.
> Regards Kjell Arne Johansen
>|||Hi
Yes I have an option to create backup with unique filenames also but I want
to know if there is anything I can use in SQL Server to do this for me and i
f
INIT and NOSKIP or other options can be used.
Kjell Arne
"Uri Dimant" wrote:

> Hi
> What I would do If I were you :-))))) just create .BAK file with GEDDATE()
> contacinated , so later on you can delete those files based on file name.
>
>
> "Kjell Arne Johansen" <KjellArneJohansen@.discussions.microsoft.com> wrote
in
> message news:6594778E-E17A-4304-AFB1-DFF2D0C8BFD6@.microsoft.com...
>
>

Scheduled backup in SQL Server 2005 Express

SQL Server 2005 Express does not have any possibilities to schedule backup so
I have made a simple application for scheduling backup, running a stored
procedure in my database.
The procedure backup up to the same backup device so all backup sets are
stored in the same file. RETAINDAYS is set to 365.
In the â'Restore Databaseâ' dialog in SQL Server 2005 Management Studio
Express I can se all backup sets in the backup file and also the â'Expirationâ'
date for each backup set.
I thought that setting option INIT and NOSKIP would overwrite expired backup
sets but instead I get an error message â'the medium on device <device>
expires on <date> and cannot be overwritten.
I though that new backup sets would be appended until a backup set expires
but it does not look like that.
Any suggestion on how to preserve backup sets for some days and then
overwrite it?
Help is appreciated.
Regards Kjell Arne JohansenHi
What I would do If I were you :-))))) just create .BAK file with GEDDATE()
contacinated , so later on you can delete those files based on file name.
"Kjell Arne Johansen" <KjellArneJohansen@.discussions.microsoft.com> wrote in
message news:6594778E-E17A-4304-AFB1-DFF2D0C8BFD6@.microsoft.com...
> SQL Server 2005 Express does not have any possibilities to schedule backup
> so
> I have made a simple application for scheduling backup, running a stored
> procedure in my database.
> The procedure backup up to the same backup device so all backup sets are
> stored in the same file. RETAINDAYS is set to 365.
> In the ?Restore Database? dialog in SQL Server 2005 Management Studio
> Express I can se all backup sets in the backup file and also the
> ?Expiration?
> date for each backup set.
> I thought that setting option INIT and NOSKIP would overwrite expired
> backup
> sets but instead I get an error message ?the medium on device <device>
> expires on <date> and cannot be overwritten.
> I though that new backup sets would be appended until a backup set expires
> but it does not look like that.
> Any suggestion on how to preserve backup sets for some days and then
> overwrite it?
> Help is appreciated.
> Regards Kjell Arne Johansen
>|||Hi
Yes I have an option to create backup with unique filenames also but I want
to know if there is anything I can use in SQL Server to do this for me and if
INIT and NOSKIP or other options can be used.
Kjell Arne
"Uri Dimant" wrote:
> Hi
> What I would do If I were you :-))))) just create .BAK file with GEDDATE()
> contacinated , so later on you can delete those files based on file name.
>
>
> "Kjell Arne Johansen" <KjellArneJohansen@.discussions.microsoft.com> wrote in
> message news:6594778E-E17A-4304-AFB1-DFF2D0C8BFD6@.microsoft.com...
> > SQL Server 2005 Express does not have any possibilities to schedule backup
> > so
> > I have made a simple application for scheduling backup, running a stored
> > procedure in my database.
> > The procedure backup up to the same backup device so all backup sets are
> > stored in the same file. RETAINDAYS is set to 365.
> > In the â'Restore Databaseâ' dialog in SQL Server 2005 Management Studio
> > Express I can se all backup sets in the backup file and also the
> > â'Expirationâ'
> > date for each backup set.
> > I thought that setting option INIT and NOSKIP would overwrite expired
> > backup
> > sets but instead I get an error message â'the medium on device <device>
> > expires on <date> and cannot be overwritten.
> > I though that new backup sets would be appended until a backup set expires
> > but it does not look like that.
> > Any suggestion on how to preserve backup sets for some days and then
> > overwrite it?
> >
> > Help is appreciated.
> >
> > Regards Kjell Arne Johansen
> >
>
>

Scheduled Backup for SQL Server Express

Not sure if this is the right forum, so please correct me if I'm in error.
I've written a Timeclock application in VB6 for our small chain of retail
stores and storing the data in a SQL Server Express database. All is
working well, but I want to perform a nighly backup of the database and
there appears to be no Maintenance Plan setup wizard in SQL Server Express.
Can anyone provide me with a query that I can launch at a scheduled time to
perform this or another alternative.
Thank you,
BarryThere is no SQL Server Agent in Express edition of SQL Server 2005, so no
scheduled tasks can be performed using standard tools. You may use OS
scheduler and SQLCMD to do this job or write your own backup app. Or, if
your Express instances can be accessed as linked servers from Standard or
Enterprise instance, you may do so by scheduling remote procedure calls on
this instance.
WBR, Evergray
--
Words mean nothing...
"BCS" <bswedeen@.tayloroil.com> wrote in message
news:NgmJf.21119$no3.16791@.tornado.southeast.rr.com...
> Not sure if this is the right forum, so please correct me if I'm in error.
> I've written a Timeclock application in VB6 for our small chain of retail
> stores and storing the data in a SQL Server Express database. All is
> working well, but I want to perform a nighly backup of the database and
> there appears to be no Maintenance Plan setup wizard in SQL Server
> Express.
> Can anyone provide me with a query that I can launch at a scheduled time
> to
> perform this or another alternative.
> Thank you,
> Barry
>|||The command to do a backup is BACKUP and you can see all the details in
BooksOnLine. But which options you use and the exact syntax depends on
exactly what you want to do and how. You might want to have a look at BOL
under BACKUP to get an idea what you want first to see what is available.
Andrew J. Kelly SQL MVP
"BCS" <bswedeen@.tayloroil.com> wrote in message
news:NgmJf.21119$no3.16791@.tornado.southeast.rr.com...
> Not sure if this is the right forum, so please correct me if I'm in error.
> I've written a Timeclock application in VB6 for our small chain of retail
> stores and storing the data in a SQL Server Express database. All is
> working well, but I want to perform a nighly backup of the database and
> there appears to be no Maintenance Plan setup wizard in SQL Server
> Express.
> Can anyone provide me with a query that I can launch at a scheduled time
> to
> perform this or another alternative.
> Thank you,
> Barry
>|||You could use a combination of SQL statements and Scheduled Tasks:
CREATE PROCEDURE nightlybackup
AS
BACKUP DATABASE [yourdb]
TO DISK = 'c:\backups\dbbackup.dat'
BACKUP LOG [yourdb]
TO DISK = 'c:\backups\dblogbackup.dat'
Now create a cmd script; run the below at a command prompt (all on one line,
of course):
echo osql -d [yourdb] -E -Q "EXEC
dbo.nightlybackup">>c:\backups\nightlybackup.cmd
Now add it as a scheduled task (all on one line again):
schtasks /create /tn nightlybackup /tr c:\backups\nightlybackup.cmd /sc
daily /st 00:05:00
This will do a daily backup at 5 minutes after midnight. Do all of this
logged on as a local administrator.
"BCS" wrote:

> Not sure if this is the right forum, so please correct me if I'm in error.
> I've written a Timeclock application in VB6 for our small chain of retail
> stores and storing the data in a SQL Server Express database. All is
> working well, but I want to perform a nighly backup of the database and
> there appears to be no Maintenance Plan setup wizard in SQL Server Express
.
> Can anyone provide me with a query that I can launch at a scheduled time t
o
> perform this or another alternative.
> Thank you,
> Barry
>
>|||Thanks to everyone for your input.
Barry
"Mark Williams" <MarkWilliams@.discussions.microsoft.com> wrote in message
news:BD7B78CE-DB95-4E1D-89FC-41F689E94725@.microsoft.com...
> You could use a combination of SQL statements and Scheduled Tasks:
> CREATE PROCEDURE nightlybackup
> AS
> BACKUP DATABASE [yourdb]
> TO DISK = 'c:\backups\dbbackup.dat'
> BACKUP LOG [yourdb]
> TO DISK = 'c:\backups\dblogbackup.dat'
> Now create a cmd script; run the below at a command prompt (all on one
line,
> of course):
> echo osql -d [yourdb] -E -Q "EXEC
> dbo.nightlybackup">>c:\backups\nightlybackup.cmd
> Now add it as a scheduled task (all on one line again):
> schtasks /create /tn nightlybackup /tr c:\backups\nightlybackup.cmd /sc
> daily /st 00:05:00
> This will do a daily backup at 5 minutes after midnight. Do all of this
> logged on as a local administrator.
> --
> "BCS" wrote:
>
error.
retail
Express.
to

Scheduled Backup for SQL Server express

Has anyone developed a script (that they're willing to share) that does a
scheduled backup of a SQL Server Express database and that automatically
generates a "dated" backup file - i.e. a new backup file each day as opposed
to a single one that gets overwritten?
Thankshttp://www.sqldbatips.com/showarticle.asp?ID=27
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Sam Malone" <the_sam_malone@.hotmail.com> wrote in message
news:%23keAXwcdGHA.4932@.TK2MSFTNGP03.phx.gbl...
> Has anyone developed a script (that they're willing to share) that does a
scheduled backup of a
> SQL Server Express database and that automatically generates a "dated" bac
kup file - i.e. a new
> backup file each day as opposed to a single one that gets overwritten?
> Thanks
>|||Thanks VERY much, Tibor.
I haven't tried this yet but, at a glance, it seems to be exactly what I
need.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OkGImYddGHA.2456@.TK2MSFTNGP04.phx.gbl...
> http://www.sqldbatips.com/showarticle.asp?ID=27
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Sam Malone" <the_sam_malone@.hotmail.com> wrote in message
> news:%23keAXwcdGHA.4932@.TK2MSFTNGP03.phx.gbl...
>|||Jasper is the one who deserves the credit. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Sam Malone" <the_sam_malone@.hotmail.com> wrote in message
news:OiUWvThdGHA.536@.TK2MSFTNGP02.phx.gbl...
> Thanks VERY much, Tibor.
> I haven't tried this yet but, at a glance, it seems to be exactly what I n
eed.
>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n message
> news:OkGImYddGHA.2456@.TK2MSFTNGP04.phx.gbl...
>

Schedule SQL script

I been trying to figure out how to do this for a while but finally given in and decided to ask here.
I am using SQL express and I think that desnt support automation of SQL scripts (please correct me if I am wrong!)

I want to run a backup script and the plan was to use a bat file and windows task scheduler. But for the life of me I cannot get the bat file to work after trying loads of different example from my searches.

Any help is apreciatedI think you are correct that express doesn't include Agent, which is the scheduling component that comes with the higher SKUs of sql server.

what does the bat file look like? are you using sqlcmd.exe? that's what I would recommend.|||hmm does it have to be called sqlcmd.exe?
I had a file called script.bat and i was writing a one line command to execute the SQL script. I really dont have any idea what im doing I was just following what some forums were saying when I searched :S

thanks|||sqlcmd.exe is a console app you can use to execute sql scripts from the cmd line. the equivalent in 2000 is osql.exe.|||I'm guessing here but I would say that you can pass parameters to sqlcmd.exe can you not? So you could call sqlcmd.exe <parameter1> <parameter2> ... from your batch file and it should run your backup commands for you.

How to connect using SQLcmd (http://msdn2.microsoft.com/en-us/library/ms188247.aspx)
How to execute commands from SQLcmd (http://msdn2.microsoft.com/en-us/library/ms253126(VS.80).aspx)
A break down of SQLcmd options (http://http://www.yukonxml.com/Reference/default.aspx?t=SQLCMD) <-- CHECK THIS ONE OUT.

Bear in mind that your batch script needs to know where the sqlcmd is run from. So it either needs to be in your PATH setting or you need to run your batch script from the same directory (not advisable).|||I really dont have any idea what im doing
You might want to take a step back and make yourself familiar with the SQL Server environment and all the tools that come with it before trying to actually implement something.
Sometimes it's quicker to read the manual first and only then start "coding", instead of trying to cleanup the mess you made because you "don't have any idea what you are doing".

Schedule SQL Express BAckup using SQL DMO

Is it possible to schedule SQL Express BAckup using SQL DMO? do I need to use

WScript.Shell,SQLDMO.SQLServer,SQLDMO.Category,SQLDMO.Job,

SQLDMO.JobStep,SQLDMO.JobSchedule?

is it possible to Schedule SQLExpress Backup using SQLDMO?SQL Express does not support SQL Agent then how can I view jobs created using SQLDMO?In management studio ,jobs option is unavailable. I have written code to add JObSchedule/job/jobStep and program is running without errors .. but no way to find out whether job is actually created and executed..

|||Because SQL Express doesn't include the SQL Server Agent the jobs you are creating can't be executed. You'd be best served to use Windows Scheduler to run the programs performing your backups.|||I would like to schedule back up programatically in ASP. If I want to use WSH , It can only run VBScript and JScript files that are .vbs or .js. It does not run .asp files. If you wish to run the VBScript code contained in an .asp file in the WSH environment, you need to remove all of the HTML tags; the <% and %> tags, and rename the file with a ".vbs" extension. Also, remove all references to any of the ASP intrinsic objects. What would be the best solution ?|||Well, since you want to schedule automatic backups, and SQL Express doesn't support SQL Agent, I think your only option is to copy the code to a VBScript file and schedule that through Windows Scheduler. The ASP code doesn't help you with the automatic processes so it's superfluous.|||Is it possible to call vbs file from ASp Application to automate back up process?|||

Hello,

A similar question. I am writing my first application. It is a small data entry and data display Form. How can the user of this deployed (if ever) application save the database to a memory stick and open it in an other instance of the same application on a different computer? It is a normal and expected when say someone writes a text, that that text can be saved, moved and opened it in any other computer -- so far the computer has a program installed which is capable to read it.

How could this be implemented? Is the application welded to a database and cann't be detached from it? Can the data itself be separated from the database as in the case of an Access or FileMaker solution?

Greetings,

Seemingly there are lot of newbies and not so newbies chasing after an answer for this problem.

Schedule SQL Express back up from ASP Page

Hello,

I need to schedule SQL Express backup from ASP Page. I was trying to use SQLDMO to schedule jobs but found that SQL Agent is not supported in Sql Express. I tried to use Scheduler.SchedulingAgent.1 to add task in schedular but getting Invalid class string error. Schedular dll is only supported in site server. What would be the best solution for me to schedule back for SQL Express?

hi,

as you already noticed, SQLExpress does not provide the native SQL Server Agent to support scheduled jobs like backups..

you have then to rely on third party scheduler, like http://www.valesoftware.com/products-express-agent.php, http://www.codeproject.com/useritems/SQLAgent.asp (free code)

personally I do recommend relying on the native OS scheduler (AT/SCHTASK) where you can define your standard schedules to execute cmd file including SQLCmd.exe calls, like
[cmd file]
SQLCmd -E -S(Local) -Q"BACKUP DATABASE [Pubs] TO DISK = N'D:\folder\Pubs.bak' WITH FORMAT, INIT, NAME = N'Pubs-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10" >>d:\folder\BckOutput.txt
[/cmd file]

which backups the Pubs database to the d:\folder\Pubs.bak file, outputting the backup execution to a text file, d:\folder\BckOutput.txt, you can later inspect for results...

additional info about this can be found at http://www.sqldbatips.com/showarticle.asp?ID=27 and http://www.sqldbatips.com/showarticle.asp?ID=29, where another free tool by an MVP fellow, Jasper Smith, is available for download to help performing backup tasks..

regards

Saturday, February 25, 2012

Schedule backup with SQL 2005 Express

How do I schedule a backup with SQL Server 2005 Express. When I right-click a database and choose Tasks -> Back Up...
I don't get the option to schedule the backup. How do I do?

hi,

SQLExpress does not provide the SQL Server Agent, thus you can not schedule a "native" backup or whatever task via a SQL Server Agent job..

you have to rely on the native OS scheduler, writing your own command file including the actual BACKUP DATABASE... statement to be executed, or on other solutions even based on the OS scheduler, like http://www.sqldbatips.com/showarticle.asp?ID=27 and http://www.sqldbatips.com/showarticle.asp?ID=29, third party solutions like http://www.lazycoding.com/products.aspx or http://www.valesoftware.com/products-express-agent.php, http://www.codeproject.com/vb/net/SQLAgent.asp, or custom solutions based on the Service Broker as indicated in http://blogs.msdn.com/rogerwolterblog/archive/2006/04/13/575974.aspx

regards|||

Ok! Thanks.

Is SQL Server 2005 Express edition the only one that do not provide the SQL Server Agent?

|||

Thats right.

See the information from here:

http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx

SQL Agent Job Scheduling Service

Jens K. Suessmeyer.

http://www.sqlserver2008.de

|||Excuse me, could you please tell me how can you backup your database use the Sql Express ?
I just want to use the osql -E order, but the system tell me that it fail to connect to the database, it may caused by the remote connections closed, but actually I allow the remote connection.
Is there another way to backup the database in the sql Express?
|||

The complete syntax for backup is proveded in Books Online, please search there for syntax help. If you are not being allowed to login, then you are either providing the wrong instance name or you are using an account that doesn't have permissions.

The most common error people make with SQL Express is that it is installed by default to an instance name, not the default instance, so you have to pass the entire instance name when connectiong:

osql -S <machine>\SQLEXPRESS -E ...

See if adding the instance name resolves your problem.

Mike

|||

If you are unfamiliar with the BACKUP syntax, you can use the UI command of SSMS(Express) and create a script which can be laterone copied to the AT job using the SQLCMD utility as Mike mentioned.

Jens K. Suessmeyer

http://www.sqlserver2005.de

Schedule backup with SQL 2005 Express

How do I schedule a backup with SQL Server 2005 Express. When I right-click a database and choose Tasks -> Back Up...
I don't get the option to schedule the backup. How do I do?

hi,

SQLExpress does not provide the SQL Server Agent, thus you can not schedule a "native" backup or whatever task via a SQL Server Agent job..

you have to rely on the native OS scheduler, writing your own command file including the actual BACKUP DATABASE... statement to be executed, or on other solutions even based on the OS scheduler, like http://www.sqldbatips.com/showarticle.asp?ID=27 and http://www.sqldbatips.com/showarticle.asp?ID=29, third party solutions like http://www.lazycoding.com/products.aspx or http://www.valesoftware.com/products-express-agent.php, http://www.codeproject.com/vb/net/SQLAgent.asp, or custom solutions based on the Service Broker as indicated in http://blogs.msdn.com/rogerwolterblog/archive/2006/04/13/575974.aspx

regards|||

Ok! Thanks.

Is SQL Server 2005 Express edition the only one that do not provide the SQL Server Agent?

|||

Thats right.

See the information from here:

http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx

SQL Agent Job Scheduling Service

Jens K. Suessmeyer.

http://www.sqlserver2008.de

|||Excuse me, could you please tell me how can you backup your database use the Sql Express ?
I just want to use the osql -E order, but the system tell me that it fail to connect to the database, it may caused by the remote connections closed, but actually I allow the remote connection.
Is there another way to backup the database in the sql Express?
|||

The complete syntax for backup is proveded in Books Online, please search there for syntax help. If you are not being allowed to login, then you are either providing the wrong instance name or you are using an account that doesn't have permissions.

The most common error people make with SQL Express is that it is installed by default to an instance name, not the default instance, so you have to pass the entire instance name when connectiong:

osql -S <machine>\SQLEXPRESS -E ...

See if adding the instance name resolves your problem.

Mike

|||

If you are unfamiliar with the BACKUP syntax, you can use the UI command of SSMS(Express) and create a script which can be laterone copied to the AT job using the SQLCMD utility as Mike mentioned.

Jens K. Suessmeyer

http://www.sqlserver2005.de

Schedule backup of data/log files

Is there an equivelant to the SQL Server Agent in SQL server express edition? If not, how can I schedule the backup of the data/log files?

Thanks,

hi,

there's not a direct equivalent.. you can resort on third pary alternatives (http://www.valesoftware.com/products-express-agent.php, never tried it), or you can go for native solutions using the OW native scheduler (AT/SCHTASKS), executing a Transact-SQL statement to perform your desired backup(s) via the SqlCMD.exe command line tool..

just create a cmd file including

[cmd file]

BACKUP DATABASE pubs TO DISK = 'c:\pubs.bak';

[/cmd file]

and schedule it via WinAT at the desired time..

voila..

regards

|||

have a look at the following post...

http://www.virtualrealm.com.au/blogs/mykre/archive/2006/09/01/SQL-Agent-for-SQL-Server-Express.aspx

This is a simple scheduler system that simulates a few of the functions of the agent and might do the job that you need.

Schedule backup of data/log files

Is there an equivelant to the SQL Server Agent in SQL server express edition? If not, how can I schedule the backup of the data/log files?

Thanks,

hi,

there's not a direct equivalent.. you can resort on third pary alternatives (http://www.valesoftware.com/products-express-agent.php, never tried it), or you can go for native solutions using the OW native scheduler (AT/SCHTASKS), executing a Transact-SQL statement to perform your desired backup(s) via the SqlCMD.exe command line tool..

just create a cmd file including

[cmd file]

BACKUP DATABASE pubs TO DISK = 'c:\pubs.bak';

[/cmd file]

and schedule it via WinAT at the desired time..

voila..

regards

|||

have a look at the following post...

http://www.virtualrealm.com.au/blogs/mykre/archive/2006/09/01/SQL-Agent-for-SQL-Server-Express.aspx

This is a simple scheduler system that simulates a few of the functions of the agent and might do the job that you need.

Tuesday, February 21, 2012

Schedule a scripted restore on 2005 Express from .bak file.

Hi i have an web app demo that allows users to add info and change attributes within a SQL 2005 Express DB. I'd like to restore a clean copy of this database every couple of hours from a .bak file using a Windows scheduled task on the server. Has anyone got a .sql script for database restoration that i could use and call using a .cmd script file? Thanks.

Hi TheGrox,

Generally speaking the sql restoration script is like this:

RESTORE DATABASE [Your_databasename] FROM DISK = N'File_Path\BCKUP.bak' WITH FILE = 1, NOUNLOAD, STATS = 10
GO

However, I don't think it can be used from a .cmd script file. To run .sql script file, you need to run it within sql server query analyzer (if you run it from a .cmd script, first it will jump up a window asking your to login to sql server, even though you enter the server name and user/password and login successfully, that sql script file will be opened there while won't be executed until you click the execute button from the GUI).

I think there are two solutions for you requirment. One solution is the easist, upgrade your sql express to a full vertion and use Server Agent-> Jobs. Run that script in a job and schedule the job to run at a sepcific time frequency. I believe it won't cost you more than 5 minutes;

The second solution is to use ado.net.Open your visual studio and create a new project, build a connection to your database first and then send the restore sqlcommand to it. Compile and build you project and after that, you create a windows schedule task and run that application regularly.

Hope my suggestion helps

|||

Hi, thanks for the suggestions. The running the .sql from a .cmd file isnt a problem, i already do that to automatically back up all DB's in my SQL Express instance by having a file called BackupDB.cmd with the following code:

CLS
ECHO OFF
ECHO Testing to make sure directories exist.
IF NOT EXIST C:\SQLBackups MD C:\SQLBackups

ECHO Complete with directory creation
ECHO **********************************************************
ECHO Backing up databases......
sqlcmd -S .\SQLEXPRESS -i c:\Windows\BackupExpress.sql -o C:\SQLbackups\backup.log
ECHO **********************************************************
ECHO Backup complete. Look in the C:\SQLBackups\Backup.log file for information.

ECHO ON

The BackupExpress.sql file is simply a script that loops through all databases on the server and creates a .bak file for each of them in the specified directory. Works nicely andmeans i dont need to reconfigure anything if a new DB is created, it is just automatically included in the backups.

So i guess i just need to create a Restore.sql script using the syntax you quoted and call it as above. The command runs under the context of a valid SQL user account specified when the scheduled task is created so login is not an issue.

The script for the BackupExpress.sql file if anyone is interested in using it is:

/**File Name: BackupExpress.sqlDescription: Backs up all databases. This script is mainly meant for SQL Express instancesThe script requires a C:\SQLBackups directory by default to backup to but can be changed with the @.OutputPath variable.Accompanying file is BackupExpress.cmd, which is used to schedule the script.**/SET QUOTED_IDENTIFIEROFF USE masterGOSET NOCOUNT ON DECLARE @.dayofweekvarchar(20)SELECT @.dayofweek =CASE datepart(dw,getdate())WHEN 1THEN'Sunday'WHEN 2THEN'Monday'WHEN 3THEN'Tuesday'WHEN 4THEN'Wednesday'WHEN 5THEN'Thursday'WHEN 6THEN'Friday'WHEN 7THEN'Saturday'ENDDECLARE @.OutputPathvarchar(500)DECLARE @.DatabaseBackupFilevarchar(500)DECLARE @.FolderNamevarchar(25)DECLARE @.DatabaseNamevarchar(25)DECLARE @.strSQLvarchar(2000)DECLARE @.hostnamevarchar(255)SET @.hostname = (select replace(convert(varchar(255),serverproperty('SERVERNAME')),'\','_'))SET @.OutputPath ='C:\SQLBackups'DECLARE cur_BackupCURSOR FOR select name fromsysdatabaseswhere name !='tempdb'OPEN cur_Backup-- Fetch the db names from CursorFETCH NEXT FROM cur_BackupINTO @.DatabaseNameWHILE@.@.FETCH_STATUS = 0BEGINSET @.DatabaseBackupFile = @.OutputPath +'\' + @.hostname +'-' + @.DatabaseName +'-' + @.dayofweek +'.bak'print @.DatabaseBackupFileSET @.strSQL ='BACKUP DATABASE '+@.DatabaseName+' TO DISK = "'+ @.DatabaseBackupFile+'" WITH RETAINDAYS = 1, NOFORMAT, INIT, NAME = N''Full Database Backup'', SKIP, NOREWIND, NOUNLOAD, STATS = 10'PRINT @.strSQLEXEC (@.strSQL)FETCH NEXT FROM cur_BackupINTO @.DatabaseNameEND-- Distroy CursorCLOSE cur_BackupDEALLOCATE cur_BackupSET NOCOUNT OFF