问题
I knew about the possibility to get backup db using SQL server agent, but I was curious to know if we can have a backup script (like batch file) that just runs in windows and gets automatic backup according to the schedule that we define?
I think for the next part we can use windows task schedule (or crontab) for run the backup script job routinely, but the most important thing is to know: is it possible to login via SQL and backup the DB just using a batch scrip file (that there not be any need for SQL management studio completely and work completely independent)?
If the answer is yes, please let me know that I have it, too.
Maybe it seems to be a silly question, but I am not so experienced about that here.
回答1:
Yes you can!.
If you have SQLServer Express version you can't use SQLAgent, so the only way is outside of the SQLServer, like a .bat file. In this link you have an example script. .Bat Script
now you can use schedule task to schedule the backup.
If you can use SQL Agent, you could create a Mainteinance Plan for a Full Backup and next create a Job in SQL Agent to run it. In this link is you can find some examples, with script and mainteinance Plan and Jobs: With SQLAgent
hope this help!
回答2:
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://docs.microsoft.com/en-us/sql/ssms/agent/schedule-a-job?view=sql-server-2017#SSMS and https://solutioncenter.apexsql.com/how-to-create-a-sql-server-scheduled-backup/ or https://www.youtube.com/watch?v=fdKePm7ImkM
Also maybe buy the SQL Server DBA exam guide and work through it, they go over it in fine detail. Hope that helps.
来源:https://stackoverflow.com/questions/41367424/sql-backup-job-script-windows-schedule-task