-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneDriveBackup.ps1
More file actions
68 lines (54 loc) · 1.73 KB
/
Copy pathOneDriveBackup.ps1
File metadata and controls
68 lines (54 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$SourcePath = "C:\Users\josebda\OneDrive\"
$BackupPath = "D:\Backup-" + (Get-Date).ToString("yyyy-MM-dd")
$BackupPath = $BackupPath + "\OneDrive\"
if (-not (Test-Path $BackupPath)) {
"Making folder $BackupPath"
MD $BackupFolder | Out-Null
}
Write-Progress -Activity "Getting File List" -PercentComplete 0
$FileList = DIR $SourcePath -Recurse -File
$Total = $FileList.Count
$Pinned = [math]::Pow(2, 19)
$Count = 0
$BadCount = 0
$FileList | % {
$File = $_.FullName
$Folder = $_.DirectoryName
$BackupFile = $File.Replace($SourcePath, $BackupPath)
$BackupFolder = $Folder.Replace($SourcePath, $BackupPath)
if (-not (Test-Path $BackupFolder)) {
"Making folder $BackupFolder"
MD $BackupFolder | Out-Null
}
Try {
attrib -U +P $File
$FileAttrib = (Dir $File).Attributes.value__
if ($FileAttrib -and $Pinned) {
Copy-Item -Path $File -Destination $BackupFile
} else {
"Attribute not reset for $File"
$CopyError = $true
}
attrib +U -P $File
$FileAttrib = (Dir $File).Attributes.value__
if (-not ($FileAttrib -and $Pinned)) {
"Attribute not reset for $File"
$CopyError = $true
} else {
$CopyError = $false
}
}
Catch {
$CopyError = $true
}
If ($CopyError) {
$BadCount++
"Error copying: $File, $Backup"
}
$Count++
If ($Count % 1000 -eq 0) {
Write-Progress -Activity "File $Count of $Total" -PercentComplete ($Count/$Total*100)
}
}
Write-Progress -Activity "Checking Files" -Completed
"Finished copying $Count files. There were $BadCount copy errors."