4

How to schedule a SQL Server 2016 database backup? The backup will be run every week.

TIA

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ben Tam
  • 587
  • 3
  • 7
  • 11

4 Answers4

3

If you are using SQL Server Express, you can't use SQL Agent, so you must do it using a script (.bat or another) and schedule it with Windows Schedule task (or another program).

If you have another version, you can create a Maintenance plan for a full backup and then with SQL Agent create a Job to run it.

See this answer for more details

Andrew Myers
  • 2,754
  • 5
  • 32
  • 40
M84
  • 727
  • 6
  • 14
2

You can create the backup script like below for you database backup:

BACKUP DATABASE your_database TO DISK = 'full.bak'
BACKUP DATABASE your_database TO DISK = 'diff.bak' WITH DIFFERENTIAL 
BACKUP LOG your_database TO DISK = 'log.bak'

Schedule it as per your requirement.

You can also use the Maintenance Plan Wizard; please refer to this link for reference:

https://msdn.microsoft.com/en-IN/library/ms191002.aspx?f=255&MSPPError=-2147217396

Andrew Myers
  • 2,754
  • 5
  • 32
  • 40
  • Should I create a text file with the following statements: – Ben Tam Dec 30 '16 at 06:28
  • BACKUP DATABASE your_database TO DISK = 'full.bak' BACKUP DATABASE your_database TO DISK = 'diff.bak' WITH DIFFERENTIAL BACKUP LOG your_database TO DISK = 'log.bak' – Ben Tam Dec 30 '16 at 06:30
  • Then put the file under Windows Scheduler to make it run periodically. – Ben Tam Dec 30 '16 at 06:31
  • About the Maintenance Plan Wizard, when I create a new maintenance plan, it ask me to enable the 'Agent XPs' component using the sp_configure procedure. Could you show me the syntax? – Ben Tam Dec 30 '16 at 06:36
0

Assuming it's not Express, you create a backup job, which you can do in SQL Server management Studio, and then schedule that backup job: https://learn.microsoft.com/en-us/sql/ssms/agent/schedule-a-job?view=sql-server-2017#SSMS

Beck
  • 1
0

Check this opensource backup windows service MFSQLBackupService, it did a great job for me. It performs daily backup, but it is too easy to patch the weekly job.

peter bence
  • 782
  • 3
  • 14
  • 34