SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating databse backups automatically in specific period of time


Creating databse backups automatically in specific period of time

Author
Message
jaryszek
jaryszek
Old Hand
Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)

Group: General Forum Members
Points: 367 Visits: 141
Hi Guys,

I am creating back ups of my database using code:

USE QlikView;  
GO
BACKUP DATABASE QlikView
TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SERVERTEST\MSSQL\Backup\QlikView.Bak'
WITH FORMAT,
MEDIANAME = 'C_SQLServerBackups',
NAME = 'Full Backup of QlikView';
GO


It is ok but question is can i create these back ups only on the last day of every month?

I can do it in VBscript and set up task scheduler on server but maybe there is a simple way to create back up in MS SQL SERVER EXPRESS using T-SQL?

Jacek
jaryszek
jaryszek
Old Hand
Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)

Group: General Forum Members
Points: 367 Visits: 141
I think that i will have to use VBscript anyway because i have to run scripts outside from SQL Server express because i do not have Job Assistant here...

Jacek
John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)

Group: General Forum Members
Points: 97299 Visits: 18431
You could use the Windows task scheduler instead. By the way, don't back up to the C drive. Make sure backups go to a different disk from the operating system and database files, and thereafter off the server all together as quickly as possible.

John
jaryszek
jaryszek
Old Hand
Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)

Group: General Forum Members
Points: 367 Visits: 141
thank you John!
Ok this is better idea to have backups on different drive then C drive.

Question about tash scheduler in Windows. I can set up the task here but some code should run MS SQL Server Query.
What can you recommendt?

Jacek
John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)

Group: General Forum Members
Points: 97299 Visits: 18431
jaryszek - Thursday, December 14, 2017 2:29 AM
Question about tash scheduler in Windows. I can set up the task here but some code should run MS SQL Server Query.
What can you recommendt?

Jacek

Have a look at this. It's a command-line utility for running SQL queries. It'll be available on your server by default.

John

jaryszek
jaryszek
Old Hand
Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)

Group: General Forum Members
Points: 367 Visits: 141
Thank you John,

I will test it !
Jacek
goher2000
goher2000
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2385 Visits: 1284
another way of doing backup for all databases, I use this for SQL express backup via sqlcmd/task schedular, BTW you can use SQL agent from standard/developer/enterprise edition to take backup of SQL express instance provided appropriate ports are open and SQL agent have access to express edition/server.


declare @cmd varchar(5000)
select @cmd ='if ''tempdb'' <> cast(''?'' as nvarchar) backup database [?] to disk =''x:\sql_backup\?\?_2017_06_15.bak'''
PRINT @cmd
exec sp_msforeachdb @cmd



Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (271K reputation)SSC Guru (271K reputation)SSC Guru (271K reputation)SSC Guru (271K reputation)SSC Guru (271K reputation)SSC Guru (271K reputation)SSC Guru (271K reputation)SSC Guru (271K reputation)

Group: General Forum Members
Points: 271611 Visits: 41183

My concern is only backing up the database once a month. If you don't mind losing almost one months data due to a failure just before your monthly backup, you really should backup the database more frequently.



Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
jaryszek
jaryszek
Old Hand
Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)Old Hand (367 reputation)

Group: General Forum Members
Points: 367 Visits: 141
Hi Guys,

thank you!
I do not have SQL server Agent and standard SQL edition.

This code:
declare @cmd varchar(5000)
select @cmd ='if ''tempdb'' <> cast(''?'' as nvarchar) backup database [?] to disk =''x:\sql_backup\?\?_2017_06_15.bak'''
PRINT @cmd
exec sp_msforeachdb @cmd


is for SQL Server Agent or cmd task ?

Best Wishes,
Jacek
GilaMonster
GilaMonster
SSC Guru
SSC Guru (669K reputation)SSC Guru (669K reputation)SSC Guru (669K reputation)SSC Guru (669K reputation)SSC Guru (669K reputation)SSC Guru (669K reputation)SSC Guru (669K reputation)SSC Guru (669K reputation)

Group: General Forum Members
Points: 669253 Visits: 48431
That's T-SQL, so no, it won't run in command line.
You can run it via the util that John mentioned.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search