Sql-server – Schedule database backup question

backupjobsscheduled-taskssql server

Good day. This may be a stupid question and you can give me a stupid answer if you need to. I know you can schedule a task to backup a sql database at logon, shutdown, specific time, etc. But What I would like to know is the following:

Is it possible to set a sql database to run at a specific time but if there is a power failure it will run when the pc/server comes back up?

So for example I schedule a full database backup on say Friday evening at 18:00 (an hour after everyone has left), but before the scheduled time there is a power outage and the ups shuts down the server (we have it configured to shutdown the server if our generator is not started in 30 minutes) and once power is back the server automatically starts up but it is after the scheduled backup time, is there a way to get it run at boot.

This isn't mission critical but more of a piece of mind/convenience thing.

TLDR – want to know if a scheduled task will run at boot as server could be powered off due to lack of electricity.

Best Answer

You can schedule an agent job to run at startup (there's an agent schedule for that), but you would have to add logic to the job to see if it "missed" the previous schedule. for instance, you can check the backup history for the relevant database and see how old the most recent backup is, and then conditionally perform the backup.