-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackItUp.ps1
97 lines (89 loc) · 3.43 KB
/
BackItUp.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
$moviesToBackup = @()
$scriptsToBackup = @()
$GitHubBackup = @()
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
$LogFile = (Join-Path "C:\Logs\" -ChildPath "$($MyInvocation.MyCommand.Name).log")
function LogWrite($logString)
{
Add-content $Logfile -value ((Get-Date).toString("yyyy/MM/dd HH:mm:ss") + ": $logString ")
Write-Host $logString
}
LogWrite("`
#######################################################################`
###################### Start ######################`
#######################################################################`
")
function backupMovies(){
$moviesToBackup = (gci T:\Movies\ | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-14)} ).FullName
Try{
foreach ($movie in $moviesToBackup){
LogWrite("Copied Movie <$($movie)> to E:\Movies\")
Copy-Item -Path $movie -Destination "E:\Movies\" -Force -Recurse
}
}
Catch{
LogWrite("ERROR OCCURRED: $_.Exception.Message")
}
}
function backupScripts(){
$scriptsToBackup = (gci C:\Users\vm305\Desktop\Scripts1 -Recurse).FullName
Try{
foreach ($script in $scriptsToBackup){
LogWrite("Copied Script <$($script)> to T:\Files\Scripts1\")
Copy-Item -Path $script -Destination "T:\Files\Scripts1\" -Force -Recurse
LogWrite("Copied Script <$($script)> to E:\Files\Scripts1")
Copy-Item -Path $script -Destination "E:\Files\Scripts1\" -Force -Recurse
}
}
Catch{
LogWrite("ERROR OCCURRED: $_.Exception.Message")
}
}
function backupGitHub(){
$GitHubBackup = (gci C:\Users\vm305\Documents\GitHub -Directory -Recurse | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-14)}).FullName
Try{
foreach($item in $GitHubBackup){
LogWrite("Copied Code <$($item)> to T:\Files\Github\")
Copy-Item $item -Destination "T:\Files\GitHub\" -Force -Recurse
LogWrite("Copied Code <$($item)> to E:\Files\GitHub\")
Copy-Item -Path $item -Destination "E:\Files\GitHub\" -Force -Recurse
}
}
Catch{
LogWrite("ERROR OCCURRED: $_.Exception.Message")
}
}
function backupMiscFiles(){
$iso = (gci D:\ISOs -Recurse -File).FullName
$kee = (gci D:\KeePass -Recurse).FullName
Try{
foreach($item in $iso){
LogWrite("Copied File <$($item)> to T:\Files\ISOs\")
Copy-Item $item -Destination "T:\Files\ISOs\" -Force -Recurse
}
foreach($item in $kee){
LogWrite("Copied File <$($item)> to T:\Files\KeePass")
Copy-Item $item -Destination "T:\Files\KeePass" -Force -Recurse
}
}
Catch{
LogWrite("ERROR OCCURRED: $_.Exception.Message")
}
}
LogWrite("<-----------Running Inventory----------->")
C:\Users\vm305\Desktop\Scripts1\inventory.ps1
LogWrite("<-----------Going to start backing up Movies----------->")
backupMovies
LogWrite("<-----------Going to start backing up Scripts----------->")
backupScripts
LogWrite("<-----------Going to start backing up GitHub----------->")
backupGitHub
LogWrite("<-----------Going to start backing up Misc files----------->")
backupMiscFiles
$stopwatch.Stop()
LogWrite("Total time: <$($stopwatch.Elapsed.TotalSeconds)>")
LogWrite("`
#######################################################################`
####################### End #######################`
#######################################################################`
")