-
Notifications
You must be signed in to change notification settings - Fork 0
/
Backup-myDotfilesAll.ps1
41 lines (39 loc) · 1.27 KB
/
Backup-myDotfilesAll.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
function backup-myDotfilesAll {
<#
.Description
Use Git-Archive to back up in different formats
#>
param([switch]$All, [switch]$Move)
if (Test-Path .\.git\) {
Write-Verbose "Determined this is a git repo
Backing up using `"git-archive`""
if (Get-Command git -ErrorAction ignore) {
# Create multiple types of archives.
# If user selects $All, make all types
# Else just `zip` format.
if ($All) {
<#
If using git-archive on windows, it uses the base version of tar installed
on Windows systems, which only has zlib compression library attached.
This means only tar.gz is available unless you link git-archive to a
different tar program.
You can always just create a tarfile and separately compress it with
a different program.
#>
$formats = @("zip", "tar.gz"<#, "tar.xz", "tar"#>)
}
else {
$formats = "zip"
}
foreach ($fmt in $formats) {
# Date the output
git archive -o "MyDotfilesGit-$(Get-Date -Format FileDate).$fmt" HEAD
}
if ($Move) {
Write-Error -Category NotImplemented "Check back later"
}
}
else { Write-Error -Category NotInstalled "Need git installed" }
}
else { return Write-Error "Not a git repository" }
}