Compare commits
2 Commits
939ad00b1a
...
74d3282fd1
Author | SHA1 | Date |
---|---|---|
DoTheEvo | 74d3282fd1 | 1 month ago |
DoTheEvo | f524b86606 | 1 month ago |
Binary file not shown.
@ -1,44 +1,50 @@
|
||||
# v0.2
|
||||
# Before using this script, create a repo, note the setting of a password
|
||||
# kopia repo create filesystem --path C:\kopia_repo --password aaa --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs
|
||||
# kopia repo create filesystem --path C:\kopia_repo --password aaa
|
||||
|
||||
# for backblaza b2
|
||||
# kopia repository create b2 --bucket=rakanishu --key-id=001496285081a7e0000000003 --key=K0016L8FAMRp/F+6ckbXIYpP0UgTky0 --password aaa
|
||||
|
||||
# useful commands:
|
||||
# - kopia repo status
|
||||
# - kopia repo connect filesystem --path C:\kopia_repo -p aaa
|
||||
# - kopia snap list -all
|
||||
# - kopia snap list --all
|
||||
# - kopia mount all K:
|
||||
# mounting should be used as non-admin user, weird windows thing
|
||||
# or one does not see the drive, in that case:
|
||||
# - net use - shows path that can be pasted to explorer or browser
|
||||
|
||||
# mounting might need be executed as non-admin user, weird windows thing
|
||||
# if one does not see the drive:
|
||||
# - 'net use' shows path that can be pasted to explorer or browser
|
||||
# \\127.0.0.1@51295\DavWWWRoot
|
||||
|
||||
# logs location is set C:\Kopia\Kopia_Logs for every command
|
||||
# if it was not manually set then it would be
|
||||
# C:\Windows\System32\config\systemprofile\AppData
|
||||
|
||||
#
|
||||
|
||||
# to backup multiple targets/paths:
|
||||
# - [array]$BACKUP_THIS = 'C:\Test','C:\users','C:\blabla'
|
||||
|
||||
$REPOSITORY_PATH = 'C:\kopia_repo'
|
||||
$KOPIA_PASSWORD = 'aaa'
|
||||
[array]$BACKUP_THIS = 'C:\Test'
|
||||
[array]$BACKUP_THIS = 'C:\test'
|
||||
$LOG_PATH = 'C:\Kopia\Kopia_Logs'
|
||||
$USE_SHADOW_COPY = $false
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
kopia repository connect filesystem --path $REPOSITORY_PATH --password $KOPIA_PASSWORD --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs
|
||||
$Env:KOPIA_LOG_DIR = $LOG_PATH
|
||||
|
||||
kopia repository connect filesystem --path $REPOSITORY_PATH --password $KOPIA_PASSWORD
|
||||
# kopia repository connect b2 --bucket=kopia-repo-rakanishu --key-id=001496285081a7e0000000003 --key=K0016L8FAMRp/F+6ckbXIYpP0UgTky0
|
||||
|
||||
kopia policy set --global --compression=zstd-fastest --keep-annual=0 --keep-monthly=12 --keep-weekly=8 --keep-daily=14 --keep-hourly=0 --keep-latest=3 --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs
|
||||
kopia policy set --global --compression=zstd-fastest --keep-annual=0 --keep-monthly=12 --keep-weekly=0 --keep-daily=14 --keep-hourly=0 --keep-latest=3
|
||||
|
||||
if ($USE_SHADOW_COPY) {
|
||||
kopia policy set --global --enable-volume-shadow-copy=when-available
|
||||
}
|
||||
|
||||
foreach ($path in $BACKUP_THIS) {
|
||||
if ($USE_SHADOW_COPY) {
|
||||
kopia policy set $BACKUP_THIS --before-folder-action "powershell -WindowStyle Hidden C:\Kopia\win_vss_before.ps1" --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs
|
||||
kopia policy set $BACKUP_THIS --after-folder-action "powershell -WindowStyle Hidden C:\Kopia\win_vss_after.ps1" --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs
|
||||
}
|
||||
kopia snapshot create $path --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs
|
||||
kopia snapshot create $path --file-log-level=info
|
||||
}
|
||||
|
||||
kopia repository disconnect --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs
|
||||
kopia repository disconnect
|
||||
|
@ -1,18 +0,0 @@
|
||||
if ($args.Length -eq 0) {
|
||||
$kopiaSnapshotId = $env:KOPIA_SNAPSHOT_ID
|
||||
} else {
|
||||
$kopiaSnapshotId = $args[0]
|
||||
}
|
||||
|
||||
if (([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
|
||||
$mountPoint = Get-Item "${PSScriptRoot}\${kopiaSnapshotId}"
|
||||
$mountedVolume = $mountPoint.Target
|
||||
|
||||
cmd /c rmdir $mountPoint
|
||||
Get-CimInstance -ClassName Win32_ShadowCopy | Where-Object { "$($_.DeviceObject)\" -eq "\\?\${mountedVolume}" } | Remove-CimInstance
|
||||
} else {
|
||||
Start-Process 'powershell' '-f', $MyInvocation.MyCommand.Path, $kopiaSnapshotId -Verb RunAs -WindowStyle Hidden -Wait
|
||||
if ($proc.ExitCode) {
|
||||
exit $proc.ExitCode
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
if ($args.Length -eq 0) {
|
||||
$kopiaSnapshotId = $env:KOPIA_SNAPSHOT_ID
|
||||
$kopiaSourcePath = $env:KOPIA_SOURCE_PATH
|
||||
} else {
|
||||
$kopiaSnapshotId = $args[0]
|
||||
$kopiaSourcePath = $args[1]
|
||||
}
|
||||
|
||||
$sourceDrive = Split-Path -Qualifier $kopiaSourcePath
|
||||
$sourcePath = Split-Path -NoQualifier $kopiaSourcePath
|
||||
# use Kopia snapshot ID as mount point name for extra caution for duplication
|
||||
$mountPoint = "${PSScriptRoot}\${kopiaSnapshotId}"
|
||||
|
||||
if (([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
|
||||
$shadowId = (Invoke-CimMethod -ClassName Win32_ShadowCopy -MethodName Create -Arguments @{ Volume = "${sourceDrive}\" }).ShadowID
|
||||
$shadowDevice = (Get-CimInstance -ClassName Win32_ShadowCopy | Where-Object { $_.ID -eq $shadowId }).DeviceObject
|
||||
if (-not $shadowDevice) {
|
||||
# fail the Kopia snapshot early if shadow copy was not created
|
||||
exit 1
|
||||
}
|
||||
|
||||
cmd /c mklink /d $mountPoint "${shadowDevice}\"
|
||||
} else {
|
||||
$proc = Start-Process 'powershell' '-f', $MyInvocation.MyCommand.Path, $kopiaSnapshotId, $kopiaSourcePath -PassThru -Verb RunAs -WindowStyle Hidden -Wait
|
||||
if ($proc.ExitCode) {
|
||||
exit $proc.ExitCode
|
||||
}
|
||||
}
|
||||
|
||||
Write-Output "KOPIA_SNAPSHOT_PATH=${mountPoint}${sourcePath}"
|
Binary file not shown.
Loading…
Reference in New Issue