Asked by:
Batch to backup database

Question
-
User66371569 posted
Hi i have sql server express and mangament studio
i want simple batch to backup my database
i want name comes like this
Mm-09-03-2019
and want my batch stored in D:\ driver
How can i do thatSunday, March 10, 2019 3:24 PM
All replies
-
User475983607 posted
Hi i have sql server express and mangament studio
i want simple batch to backup my database
i want name comes like this
Mm-09-03-2019
and want my batch stored in D:\ driver
How can i do thatPretty simple. Use osql or cmdsql to build a command line .bat file. Then schedule the task to run through Windows Task scheduler or the SQL agent.
https://docs.microsoft.com/en-us/sql/tools/osql-utility?view=sql-server-2017
https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-2017
Simply lookup bat command for naming files and working with dates. There are tons of online resources.
Sunday, March 10, 2019 5:23 PM -
User-893317190 posted
Hi thepast,
If you want to back up your database using ssms,you could right click the database in your ssms -> choose tasks -> choose generate scripts .
Then in the pop-up wizard, choose Choose Objects, click next , then you could choose where to export the script.
You could also specify the vision of your script (whether sqlserver2008 ,sqlserver2017...)
In the save script wizard, please click Advanced , choose script for server version , and then choose your remove server's version.
Or you could choose to backup when choosing task.
Best regards,
Ackerly Xu
Monday, March 11, 2019 5:28 AM -
User66371569 posted
not through ssms I want it batch file to schedule it automatic
Monday, March 11, 2019 6:48 AM -
User-893317190 posted
Hi thepast,
I'm sorry , I misunderstood what you mean.
Just as mgebhard has said , you should use .bat and windows task schedule.
For how to use taskschedule, you could refer to
https://www.digitalcitizen.life/how-create-task-basic-task-wizard
About how to write the backup t-sql, please refer to
https://database.guide/how-to-backup-a-sql-server-database-using-t-sql/
You could also refer to the link below
https://stackoverflow.com/questions/7201061/how-to-create-jobs-in-sql-server-express-edition
Best regards,
Ackerly Xu
Monday, March 11, 2019 7:24 AM