Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be used to script a db restore #529

Open
dkozlowski569 opened this issue Sep 15, 2021 · 2 comments
Open

Can this be used to script a db restore #529

dkozlowski569 opened this issue Sep 15, 2021 · 2 comments

Comments

@dkozlowski569
Copy link

Can MSQL-CLI be used to automate the restore of a DB ?

@dkozlowski569 dkozlowski569 changed the title Can this be used script a db retore Can this be used script a db restore Sep 15, 2021
@dkozlowski569 dkozlowski569 changed the title Can this be used script a db restore Can this be used to script a db restore Sep 15, 2021
@chrisg123
Copy link

I would assume so. I haven't scripted it but I do it manually with the following:

ALTER DATABASE "THE_DB" SET OFFLINE WITH ROLLBACK IMMEDIATE

RESTORE DATABASE "THE_DB" FROM DISK = 'some\path\to\my.bak' WITH REPLACE,STATS=1

ALTER DATABASE "TH_DB" SET ONLINE

You can run this query to see the restore progress

SELECT
   session_id as SPID, command, a.text AS Query, start_time, percent_complete,
   dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time
FROM sys.dm_exec_requests r
   CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) a
WHERE r.command in ('BACKUP DATABASE','RESTORE DATABASE')

If you take a look at mssql-cli -h the -i or --input_file parameters should let you pass in a script.

@mauro-miatello
Copy link

RESTORE FROM DISK runs into server, so if the mssql-cli connection is from remote I think this doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants