sqlrus.com
Backup & Restore Script with a Move | John Morehouse
Ok, I'll admit it. I like scripts that are handy and do things. Especially if the scripts make my life easier. Now, not every environment is the same. Instances get configured differently or things change just due to the nature of the business. In a previous life I would routinely have to backup a database and restore it to another server. However, the server I was using to restore to had a different drive configuration. It happens. Anyway, I wanted a script that would give me A backup statement A restore statement with the appropriate MOVE switch This would allow me to easily execute the backup statement and then on the target server execute the restore statement. Since the restore statement already had the appropriate MOVE switch provided, I didn't have to manually compose the statement. First, we will declare some variables just to make things a little cleaner and easier [crayon-5ce542274f74e554595724/] Next, we'll use a CTE to get the database name(s) and the file paths.