SQLServer backup and restore

备份

Backup-SqlDatabase -ServerInstance $ServerInstance -Database $DBName -BackupFile $BackupFilePath -Credential $DBCredential -Incremental

还原

Restore-SqlDatabase -ServerInstance $ServerInstance -Database $DBName -BackupFile $BackupFilePath

实际使用以下脚本,脚本自己写,灵活。

Invoke-Sqlcmd "USE [master]
ALTER DATABASE [DATABASENAME] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [DATABASENAME] FROM  DISK = N'PATH\DATABASENAME.bak' WITH  FILE = 1,  NORECOVERY,  NOUNLOAD,  STATS = 5
RESTORE DATABASE [DATABASENAME] FROM  DISK = N'PATH\DATABASENAME.inc' WITH  FILE = 1,  NOUNLOAD,  STATS = 5
ALTER DATABASE [DATABASENAME] SET MULTI_USER
GO

Ref

https://docs.microsoft.com/en-us/powershell/module/sqlserver/?view=sqlserver-ps

posted @ 2022-07-13 16:36  talentzemin  阅读(40)  评论(0编辑  收藏  举报