Windows轻型目录(AD LDS)的备份恢复

 

新建BackUpADLDS.ps1:

 

$Bdate = Get-Date -Format yyyy-MM-dd
$backupPath = "e:\Backup\ADLDS"
$InstanceName= "MYADLDS"
$numberOfBackupsDaysToKeep = 61
#Create a backup of the ADLDS instance
dsdbutil "Activate Instance $InstanceName" ifm "Create Full $BackupPath\Temp" quit quit
start-sleep -seconds 600
Move-Item $BackupPath\Temp\adamntds.dit $BackupPath
Rename-Item $BackupPath\adamntds.dit -newname $Bdate"adamntds.dit"
cd $BackupPath
forfiles.exe -d $numberOfBackupsDaysToKeep -m *.dit -c "cmd /c del /q /f @FILE"
exit

 

 

执行此PowerShell脚本,会有下面的错误提示:

无法加载文件 ******.ps1,因为在此系统中禁止执行脚本。有关详细信息,请参阅 "get-help about_signing"。 

 

那么要修改about_signing,执行“set-ExecutionPolicy RemoteSigned ”:

 

执行策略更改 

执行策略可以防止您执行不信任的脚本。更改执行策略可能会使您面临 about_Execution_Policies 

帮助主题中所述的安全风险。是否要更改执行策略? 

[Y] 是(Y)[N] 否(N)[S] 挂起(S)[?] 帮助 (默认值为“Y”): y

 

新建任务计划, 操作à启动程序à程序或脚本:powershell.exe

添加参数:E:\BackupBAT\BackupADLDS.ps1

 

新建ADLDS恢复.bat

 

@echo off
:select
set /p continue="请注意adamntds.dit是否在E:\BackUp\ADLDS\adamntds.dit以及确保文件名一样.输入"Y"继续,输入"N"退出."
echo %continue%
if /i %continue%==n goto :eof else (
if /i %continue%==y goto ldsrestore else (
echo 您的输入不正确,请重新输入!&goto select
)
)
:ldsrestore
net stop CJADLDS
echo A| xcopy /os E:\BackUp\ADLDS\adamntds.dit "C:\Program Files\Microsoft ADAM\CJADLDS\data\adamntds.dit"
net start CJADLDS
exit

 

你可能感兴趣的:(备份,恢复,轻型目录,ADLDS)