-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaily_backup.ps1
55 lines (53 loc) · 2.02 KB
/
daily_backup.ps1
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
$Source = "C:\repository"
$Destion = "D:\repository_all\backup"
$NoSubDiectory = "bin", "cargo-win", "maven", "msys64", "gradle", "npm-win", "pip-win", "vimfiles"
$SkipDiectory = , ""
$Date = Get-Date -Format "yyyy-MM-dd"
$Destion = "$Destion-$Date"
New-Item "$Destion" -ItemType Directory -Force
foreach ($Directory in @(Get-ChildItem -Attributes Directory $Source)) {
if ($SkipDiectory.Contains($Directory.Name)) {
continue
}
if ($NoSubDiectory.Contains($Directory.Name)) {
$DirectoryInfo = Get-ChildItem $Directory.FullName | Measure-Object
if ($DirectoryInfo.count -eq 0){
continue
}
$DestionZipName = "$Destion\$($Directory.Name).7z"
if (Test-Path $DestionZipName) {
"$($DestionZipName) already exits."
continue
}
$Compress = @{
Path = $Directory.FullName
Format = "SevenZip"
CompressionLevel = "Normal"
ArchiveFileName = $DestionZipName
}
Compress-7Zip @Compress
} else {
foreach ($SubDirectory in @(Get-ChildItem -Attributes Directory $Directory.FullName)) {
$DirectoryInfo = Get-ChildItem $SubDirectory.FullName | Measure-Object
if ($DirectoryInfo.count -eq 0){
continue
}
if (-Not (Test-Path "$Destion\$($Directory.Name)")) {
"$Destion\$($Directory.Name) not exits."
New-Item -ItemType Directory "$Destion\$($Directory.Name)"
}
$DestionZipName = "$Destion\$($Directory.Name)\$($SubDirectory.Name).7z"
if (Test-Path $DestionZipName) {
"$($DestionZipName) already exits."
continue
}
$Compress = @{
Path = $SubDirectory.FullName
Format = "SevenZip"
CompressionLevel = "Normal"
ArchiveFileName = $DestionZipName
}
Compress-7Zip @Compress
}
}
}