![adventureworks2012 bak adventureworks2012 bak](https://i.ytimg.com/vi/d882gInvFvw/maxresdefault.jpg)
Note: name of my database server is touch and I am connecting it with windows authentication. Here is the basic script for Backup and Restore Please adapt the script based on your environment and needs. I am demonstrating a very simple example in this blog post.
![adventureworks2012 bak adventureworks2012 bak](https://qawithexperts.com/Images/Upload/10-05-2018/done-7-min.png)
Let us see how DBA can automate their task about Backup and Restore using SQLCMD.
#Adventureworks2012 bak how to#
One thing I noticed in my career that every successful DBA knows how to automate their tasks and spend their time either playing games on a computer or learning something new! They often do this task more times than they would have ideally loved to do so. SQL SERVER – Backup and Restore Database Using Command Prompt – SQLCMDīackup and Restore is one of the core tasks for DBAs. Get-ChildItem $Path | Where-Object | Remove-Item $DatetoDelete = $CurrentDate.AddDays($Daysback)
![adventureworks2012 bak adventureworks2012 bak](https://res.cloudinary.com/lwgatsby/f_auto/www/uploads/2018/10/SSMS3-min.png)
#Create a file name based on the timestamp If(($db.Name -ne “tempdb”) -and ($status -eq “Normal”)) #Don’t want to backup the tempdb database One for backup, second for maintenance of backup files (for sure you don’t want to run out of storage space) PowerShell + SQL Job is better option in this case.