Search code examples
sql-serverdatabase-backups

What happens to SQL Server jobs that are scheduled during a backup?


Hypothetical question:

If a maintenance plan is scheduled to run a full backup of several databases while they're online, and during this time other jobs are scheduled to run (stored procedures, SSIS packages etc), what happens to these jobs during the backup?

I'm guessing either:

  • The job is paused until the backup is completed, then they're run in the same order they were scheduled to.

Or

  • SQL Server works out what tables will be affected by each scheduled job and backs them up after the job completes?!

Or

  • SQL Server creates a "snapshot" of all the tables before the back up starts, any changes to them (including changes made by the jobs run during the backup) are added to the transaction log, which should be backed up separately.

...are any of my ideas correct?!


Solution

  • Idea #3 is the closest to what happens. The key is that when the backup operation completes, the backup file will be in a state that allows for the restore of the database to a consistent state.

    From the documentation:

    Performing a backup operation has minimal effect on transactions that are running; therefore, backup operations can be run during regular operations. During a backup operation, SQL Server copies the data directly from the database files to the backup devices. The data is not changed, and transactions that are running during the backup are never delayed. Therefore, you can perform a SQL Server backup with minimal effect on production workloads.

    ...

    SQL Server uses an online backup process to allow for a database backup while the database is still being used. During a backup, most operations are possible; for example, INSERT, UPDATE, or DELETE statements are allowed during a backup operation.