Link to home
Start Free TrialLog in
Avatar of MichaelBalack
MichaelBalackFlag for Singapore

asked on

How to schedule backup of MS SQL 2012 Database?

This is using MS SQL Server 2012 R2 on MS Windows Server 2012 R2 server. The objective is to have a daily schedule to backing up one database into E:\DBBackups folder. I am thinking of making use of MS Task scheduler to do this scheduling backup jobs. BTW, how to write a script/batch file in order to backing up this database into E:\DBBackups folder, so as a subfolder will be created based on the date of the day? for example, for date - 15th July, a subfolder, such as 140716 was created with the latest DB backing up into it?
Please show step by step.

Appreciate for any help.
ASKER CERTIFIED SOLUTION
Avatar of Manju
Manju
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is there a reason why you need the backup directory to have the date.  The maintenance plan can be configured to create a folder for each database being backed up and it will append a date time stamp to the file name.

Additionally to creating the Backup database task you should also create a "Maintenance Cleanup Task" to delete backup files, otherwise they will pile up in the folder.

On a side note you should be backing up all your databases (system db's included), specially if this is a production system.  Even if it's a test system you want to backup at some intervals to allow you to recover if something got messed up.
Avatar of MichaelBalack

ASKER

Hi Jose,

Without a subfolder is ok. So long as there is a way to identify the backup files. Btw, can you show example on how to use this maintenance plan?

Cleanup also important as we just want keep the latest 10 copies.

thanks,
The best and easies way to do it is to use Ola Hallegren maintenance solution. Beside backup i recommend you the Index Optimisation and the Integrity Check as well, even though they are separate of one another:

https://ola.hallengren.com/

For the backup use the backup stored procedure and the job that it automatically creates for you if you use the master script(the one that isntalles the whole solution, not just the backup). After you ran it you just go and set a schedule to the USER_DATABASES Backuo Job. You will have to edit the backup location in the Job to the one you want to use.
Thanks for expert - Manju, in suggesting using MS SQL Management studio maintenance plan. I using the 2 main tasks - maintenance cleanup, and full database backup, and they can fulfill my objective.