update
parent
b52f9b30ec
commit
33d4ac66d8
@ -1,11 +0,0 @@
|
||||
$REPOSITORY_PATH = 'C:\Backup'
|
||||
$BACKUP_THIS = 'C:\Users'
|
||||
$KOPIA_PASSWORD='aaa'
|
||||
|
||||
kopia policy set $BACKUP_THIS --before-folder-action "powershell -WindowStyle Hidden C:\win_vss_before.ps1"
|
||||
kopia policy set $BACKUP_THIS --after-folder-action "powershell -WindowStyle Hidden C:\win_vss_after.ps1"
|
||||
|
||||
kopia repository connect filesystem --path $REPOSITORY_PATH --password $KOPIA_PASSWORD
|
||||
kopia snapshot create $BACKUP_THIS
|
||||
kopia repository disconnect
|
||||
|
@ -0,0 +1,49 @@
|
||||
@echo off
|
||||
|
||||
:: checking if the script is run as administrator
|
||||
net session >nul 2>&1
|
||||
if %errorLevel% == 0 (
|
||||
echo - Success: Administrative permissions confirmed.
|
||||
) else (
|
||||
echo - RUN AS ADMINISTRATOR
|
||||
pause
|
||||
exit /B
|
||||
)
|
||||
|
||||
echo - powershell ExecutionPolicy changing to Bypass
|
||||
powershell.exe Set-ExecutionPolicy -ExecutionPolicy Bypass
|
||||
|
||||
echo - copying kopia.exe in to system32
|
||||
robocopy "%~dp0\" "C:\Windows\System32" "kopia.exe" /NDL /NJH /NJS
|
||||
echo.
|
||||
|
||||
echo - checking if C:\Kopia folder exists, creating it if not
|
||||
if not exist "C:\Kopia\" (
|
||||
mkdir C:\Kopia
|
||||
)
|
||||
|
||||
if exist "C:\Kopia\kopia_backup_scipt.ps1" (
|
||||
echo - C:\Kopia\kopia_backup_scipt.ps1 exists, renaming it with random suffix
|
||||
ren "C:\Kopia\kopia_backup_scipt.ps1" "kopia_backup_scipt_%random%.ps1"
|
||||
)
|
||||
|
||||
echo - copying files to C:\Kopia
|
||||
robocopy "%~dp0\" "C:\Kopia" "kopia_backup_scipt.ps1" /NDL /NJH /NJS
|
||||
robocopy "%~dp0\" "C:\Kopia" "win_vss_before.ps1" /NDL /NJH /NJS
|
||||
robocopy "%~dp0\" "C:\Kopia" "win_vss_after.ps1" /NDL /NJH /NJS
|
||||
echo.
|
||||
|
||||
if exist C:\Windows\System32\Tasks\kopia_backup_schedule (
|
||||
echo - scheduled task with that name already exists, skipping
|
||||
echo - delete the task in taskschd.msc if you want fresh import
|
||||
) else (
|
||||
echo - importing scheduled task kopia_backup_schedule
|
||||
schtasks.exe /Create /XML "%~dp0\kopia_backup_schedule.xml" /tn "kopia_backup_schedule"
|
||||
)
|
||||
|
||||
echo.
|
||||
echo --------------------------------------------------------------
|
||||
echo.
|
||||
echo DEPLOYMENT DONE, RUN THE FOLLOWING COMMAND TO INITIALIZE A REPO
|
||||
echo kopia repo create filesystem --path C:\kopia_repo --password aaa
|
||||
pause
|
Binary file not shown.
@ -0,0 +1,38 @@
|
||||
# Before using this script, initiate the repo
|
||||
# kopia repo create filesystem --path C:\kopia_repo --password aaa
|
||||
|
||||
# useful commands
|
||||
# kopia repo connect filesystem --path C:\kopia_repo -p aaa
|
||||
# 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
|
||||
# \\127.0.0.1@51295\DavWWWRoot
|
||||
|
||||
# logs location when run as task scheduler
|
||||
# C:\Windows\System32\config\systemprofile\AppData
|
||||
|
||||
# config
|
||||
# example of $BACKUP_THIS with multiple paths
|
||||
# [array]$BACKUP_THIS = 'C:\Test','C:\Test2','C:\Test3'
|
||||
|
||||
$REPOSITORY_PATH = 'C:\kopia_repo'
|
||||
$KOPIA_PASSWORD='aaa'
|
||||
[array]$BACKUP_THIS = 'C:\Test'
|
||||
$USE_SHADOW_COPY = $false
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
kopia repository connect filesystem --path $REPOSITORY_PATH --password $KOPIA_PASSWORD --enable-actions
|
||||
|
||||
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"
|
||||
kopia policy set $BACKUP_THIS --after-folder-action "powershell -WindowStyle Hidden C:\Kopia\win_vss_after.ps1"
|
||||
}
|
||||
kopia snapshot create $path --file-log-level=info
|
||||
}
|
||||
|
||||
kopia repository disconnect
|
||||
|
@ -0,0 +1,50 @@
|
||||
@echo off
|
||||
|
||||
:: checking if the script is run as administrator
|
||||
net session >nul 2>&1
|
||||
if %errorLevel% == 0 (
|
||||
echo - Success: Administrative permissions confirmed.
|
||||
) else (
|
||||
echo - RUN AS ADMINISTRATOR
|
||||
pause
|
||||
exit /B
|
||||
)
|
||||
|
||||
echo - powershell ExecutionPolicy changing to Bypass
|
||||
powershell.exe Set-ExecutionPolicy -ExecutionPolicy Bypass
|
||||
|
||||
echo - checking if C:\Kopia folder exists, creating it if not
|
||||
if not exist "C:\Kopia\" (
|
||||
mkdir C:\Kopia
|
||||
)
|
||||
|
||||
if exist "C:\Kopia\kopia_server_start.cmd" (
|
||||
echo - C:\Kopia\kopia_server_start.cmd exists, renaming it with random suffix
|
||||
ren "C:\Kopia\kopia_server_start.cmd" "kopia_backup_scipt_%random%.ps1"
|
||||
)
|
||||
|
||||
echo - copying files to C:\Kopia
|
||||
robocopy "%~dp0\" "C:\Kopia" "kopia.exe" /NDL /NJH /NJS
|
||||
robocopy "%~dp0\" "C:\Kopia" "kopia_server_start.cmd" /NDL /NJH /NJS
|
||||
robocopy "%~dp0\" "C:\Kopia" "win_vss_before.ps1" /NDL /NJH /NJS
|
||||
robocopy "%~dp0\" "C:\Kopia" "win_vss_after.ps1" /NDL /NJH /NJS
|
||||
echo.
|
||||
|
||||
if exist C:\Windows\System32\Tasks\kopia_server_backup_start (
|
||||
echo - scheduled task with that name already exists, skipping
|
||||
echo - delete the task in taskschd.msc if you want fresh import
|
||||
) else (
|
||||
echo - importing scheduled task that starts Kopia Server on boot
|
||||
schtasks /Create /XML "%~dp0\kopia_server_backup_start.xml" /tn "kopia_server_backup_start"
|
||||
)
|
||||
|
||||
echo - starting Kopia Server
|
||||
schtasks /run /tn kopia_server_backup_start
|
||||
|
||||
echo.
|
||||
echo --------------------------------------------------------------
|
||||
echo.
|
||||
echo DEPLOYMENT DONE
|
||||
echo KOPIA SERVER CAN NOW BE FIND AT WEB PAGE: localhost:51515
|
||||
echo.
|
||||
pause
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
chdir /d C:\Kopia
|
||||
start /B kopia server start --insecure --address=127.0.0.1:51515 --server-username=admin --server-password=aaa
|
@ -0,0 +1,18 @@
|
||||
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
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
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}"
|
Loading…
Reference in New Issue