$today = get-date $todayu = get-date -format ‘yyyyMMdd‘ #备份DHCP数据库 Backup-DhcpServer -ComputerName dhcp1.uxin.youxinpai.com -Path C:\Windows\system32\dhcp\backup #导出DHCP配置,恢复的时候,只用Import-DhcpServer即可 Export-DhcpServer -ComputerName dhcp1.uxin.youxinpai.com -File C:\Backup\dhcp1_export_$todayu.xml xcopy.exe /s /y C:\Backup\dhcp1_export_$todayu.xml \\192.168.200.249\D$\Backup\DHCP_Exportxcopy.exe /s /y C:\Windows\system32\dhcp\backup \\192.168.200.249\D$\Backup\DHCP_Backup
清除早于14天的数据
#清除DHCP服务器的备份文件:删除早于14天的备份文件 $Files = Get-ChildItem –Path D:\Backup\DHCP_Backup Foreach ($file in $Files) { If (((get-date) - $file.lastwritetime).days -gt 14) {Remove-Item $file.Fullname -Force -Recurse} } $Files2 = Get-ChildItem –Path D:\Backup\DHCP_Export Foreach ($file2 in $Files2) { If (((get-date) - $file2.lastwritetime).days -gt 14) {Remove-Item $file2.Fullname -Force} }
Restore-DhcpServer -ComputerName dhcpserver.contoso.com -Path C:\Windows\system32\dhcp\backup
Import-DhcpServer -ComputerName dhcpserver.contoso.com -File C:\exports\dhcpexport.xml -BackupPath C:\dhcpbackup\
参考:https://technet.microsoft.com/zh-cn/library/jj553823.aspx
时间: 2024-11-09 03:09:06