Backup, Corfu Navision 2016, How To, Information, Job, Schedule, SQL, Tip & Tricks

Schedule SQL Job for SQL Database Backup

 

Today we will see how we can schedule to take daily backup of our database.

Before i start explaining the step i am confirming the version of SQL based on which i am writing this post.

Process will remain same may be screen bit different in different versions of SQL.

SCheduleJob-1

At first we will ensure that SQL Server Agent is running, in case it is not right click and Start it.

SCheduleJob-1

Expand the SQL Server Agent Folder, Select Jobs, Right click and select New Job.

SCheduleJob-1

Provide Name & Description to your New Job.

SCheduleJob-1

Select Page Steps & New from Bottom of the page to define Step for your Job.

SCheduleJob-1

Give name to the Step.

Select Type as Transact Script (T-SQL).

Select Database Name in my case i am selecting Demo Database NAV (9-0)

Write the Script as shown below:

SCheduleJob-1

Here is the Script for your ready reference:

{– Script Start

SET QUOTED_IDENTIFIER off

select getdate() “Start Time”

set nocount on
declare @dbname varchar(36),@cmd varchar(255)

declare dbname_cursor cursor
for select name from master..sysdatabases where name = ‘Demo Database NAV (9-0)’
order by name

open dbname_cursor
fetch dbname_cursor into @dbname

while @@fetch_status = 0
begin
DECLARE @DATE VARCHAR(36)
SELECT @DATE = (select CONVERT(char(8),DATEADD(dd,-30,GETDATE()),112))
if DATABASEPROPERTYEX(@dbname,’Status’) = ‘ONLINE’
begin
select @cmd =’backup database [‘+@dbname+’] to DISK=”C:\User Data\SQL Backup\’+@dbname+’.bak” with init’;
print @cmd
execute (@cmd)
end
fetch dbname_cursor into @dbname
end

close dbname_cursor

deallocate dbname_cursor

select GETDATE() “End Time”

–Script End}

Although above script is for multipurpose like if you want to backup all database on your SQL Server, you can make small tweaking and you are done.

If you would like to backup all the databases on a particular SQL Server, then make the following changes to the code above.

Replace following line of code:

for select name from master..sysdatabases where name = ‘Demo Database NAV (9-0)’

with the following line of code:

for select name from master..sysdatabases where name != ‘tempdb’

This will create a backup file for each database on the server, except for the temp database.

Next : Switch to Advanced Page.

Define other parameters as shown in below screen as per your requirement.

SCheduleJob-1

On Selecting OK, you will return to Job window.

SCheduleJob-1

Select Schedule Page:

Define your Schedule as per your requirement.

SCheduleJob-1

Select OK to return to Job Page.

SCheduleJob-1

Select OK to close and save the JOB.

Now our Job is  created and scheduled.

You can see defined Jobs and its Status using Job Activity Monitor.

Before Job is executed

SCheduleJob-1

After executed you can see the Status as.

SCheduleJob-1

Post execution of Job here is the backup file created at defined path in the Script. Above script will overwrite the file on next execution.

If you want to create new file on every execution you need to modify the script for file name by adding timestamp or any other logic you desire.

SCheduleJob-1

I will come up with more information in my upcomming posts.

thats all for this post.

 

Advertisement
Report

The New Report Scheduling feature for end users running reports in Microsoft Dynamics Navision 2015


The new Report Scheduling feature for end users running reports:

  • End user can schedule reports for later execution.
  • User can get to his next task quicker.
  • User has an inbox part for viewing the scheduled reports.

 A. Setting up the job queue to run a report

My Customer needs to run a number of long running reports and does not want to wait for them to complete.

The scenario is simplified because a typical customer setup would involve setting up a NAS instance to process the reports.

* Open the Job Queues page.

ReportSchedule-1

* On the Home tab, in the New group, choose New to set up a new job queue

ReportSchedule-2

* In the Code field, type Reports.

* Fill in the Description field My Report Schedule.

* Leave the Job Queue Category Filter field blank.

* On the Home tab, in the Process group, choose Start Job Queue.

* Close the Job Queue Card

ReportSchedule-3

A job queue with no filter runs the reports.

In many customer installations, the reports will be picked up by the DEFAULT job queue


B. Adding the Report Inbox to the Role Center

My Customer wants easy access to the reports that he has scheduled, so he adds the Report Inbox part to the Role Center page.

* To open the Role Center page that you want to customize, in the navigation pane, choose the Home button, then choose the Role Center menu item.

* On the Application menu , choose Customize, and then Customize This Page.

* In the Available Parts pane, select Report Inbox, and then choose the Add button.

* To move the Report Inbox part to top of the second column in the Role Center layout pane, select it and then use the Move buttons.

* (Optional) To add the My Job Queue to the Role Center, in the Available Parts pane, select My Job Queue, and then choose the Add button.

* (Optional) To move the My Job Queue part below the Report Inbox in the Role Center layout pane, select it and then use the Move buttons.

ReportSchedule-4

ReportSchedule-5

* Verify that the Report Inbox appears in the Role Center.

ReportSchedule-6


C.Scheduling a report and viewing the result

* On the Role Center, on the Report tab, choose Customer Order – Summary.

* On the report request window, choose the Print button, and then choose Schedule

ReportSchedule-7

* In the Schedule a Report window that appears, in the Description field type a different text.

* In the Report Output Type field, select the down arrow, and choose PDF.

* Choose the OK button.

ReportSchedule-8

* Go to the Report Inbox on the Role Center and show that the report appears when it is finished running.

* To view the report, select it in the Report Inbox, and then choose Show.

ReportSchedule-9


D. When a scheduled report fails

* Open the Role Center.

* On the Application menu , choose Customize, and then Customize This Page.

* In the Available Parts pane, select My Job Queue, and then choose the Add button.

* To move the My Job Queue part below the Report Inbox in the Role Center layout pane, select it and then use the Move buttons

* In the Role Center, go to the My Job Queue part.

We have already done above step in above steps. Let’s continue with next step. If not already done follow the steps as defined above.

* On the Role Center, on the Reports tab, choose Price List.

* In the Sales Type field select Customer.

* To schedule the report to run later, choose the Print button, then select Schedule.

* In the Schedule a Report window, leave the default values in fields and choose the OK button.

ReportSchedule-10

* When the error shows up in the My Job Queue part, select the error, and then choose Show Error.

* Read the error message, and then choose the OK button to close it.

ReportSchedule-11

* Open the Job Queue Log Entries page.

* Filter the list to display entries whose Status is Error.

* To view the error message, point to the Error message field for the entry, or, select the entry, and then on the Home tab, choose Show Error Message.

* Return to the Role Center, and then run the Price List report again.

* On the report request window, set the Sales Type field to All Customers, choose Print, and then choose Schedule.

* In the Schedule a Report window, leave the default values in fields and choose the OK button.

* In the Report Inbox on the Role Center, view the completed report.

ReportSchedule-12