我需要一些PowerShell的帮助。 我的经验非常有限,因为我是一个sql server dba。 我目前正在做的是从2000年到2008年迁移数据库。我想从源到目标自动化.bak副本,所以我不需要进入每个文件夹并复制然后粘贴。 所以让我给出一些图片。 源目录包含文件夹abcd 。 我希望脚本从每个文件夹中读取或理想地指定文件夹名称,并按日期获取最新的.Bak完整备份并复制到目标。 目标将具有相同的文件夹,因此文件夹a的备份复制到目标文件夹a将是很好的。 之后我想做同样的事情但是将我的搜索从完全备份搜索更改为差异。 任何帮助表示赞赏。
I need some assistance with powershell . My experience is very limited as I'm a sql server dba. What I am currently doing is migrating databases across from 2000 to 2008. I want to automate the .bak copy from source to destination so I don't need to go into each folder and copy and then paste. So let me give the picture. The source directory has folders a b c d. I want the script to read from each folder or ideally specify the folder names and get the most recent .Bak full backup by date and copy to a destination. The destination will have the same folders so folder a's backup copied to destination folder a will be great. Afterwards I want to do the same but change my search from full backup search to differential. Any help is appreciated.
最满意答案
这就是我要解决的问题。 文件夹路径和目标路径的变量是根文件夹,子文件夹的变量列出每个要搜索的文件夹。
Clear-Host $ChildFolders = @('A', 'B') for($i = 0; $i -lt $ChildFolders.Count; $i++){ $FolderPath = "D:\BackupSource\" + $ChildFolders[$i] $DestinationPath = "D:\BackupDestination\" + $ChildFolders[$i] gci -Path $FolderPath -File | Sort-Object -Property LastWriteTime - Descending | Select FullName -First 1 | %($_){ $_.FullName Copy-Item $_.FullName -Destination $DestinationPath } }This is how I would address it. The vars for folderpath and destination path are the root folders and the var for childfolders list out each folder to search.
Clear-Host $ChildFolders = @('A', 'B') for($i = 0; $i -lt $ChildFolders.Count; $i++){ $FolderPath = "D:\BackupSource\" + $ChildFolders[$i] $DestinationPath = "D:\BackupDestination\" + $ChildFolders[$i] gci -Path $FolderPath -File | Sort-Object -Property LastWriteTime - Descending | Select FullName -First 1 | %($_){ $_.FullName Copy-Item $_.FullName -Destination $DestinationPath } }更多推荐
发布评论