Restore All databases from folder
#https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/blob/dev/sp_DatabaseRestore.sql
DECLARE cDatabases CURSOR
FOR SELECT name
FROM master.sys.databases sd
WHERE sd.name IN('perfstat', 'sqlnexus', 'pdb')
AND sd.[user_access_desc] = 'MULTI_USER'
AND sd.[is_in_standby] = 0;
DECLARE @DBName SYSNAME;
-- Loop through all the databases
OPEN cDatabases;
FETCH NEXT FROM cDatabases INTO @DBName;
WHILE(@@FETCH_STATUS = 0)
BEGIN
EXEC DBATasks..[sp_DatabaseRestore]
@Database = @DBName,
@BackupPathFull = '\\ServerName\d$\Program Files\Microsoft SQL Server\MSSQL12.SQL141\MSSQL\Backup\Hi\',
@RunRecovery = 1;
FETCH NEXT FROM cDatabases INTO @DBName;
END;
CLOSE cDatabases;
DEALLOCATE cDatabases;
GO
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home