diff --git a/kopia_backup/kopia_cli_deploy_win/DEPLOY.cmd b/kopia_backup/kopia_cli_deploy_win/DEPLOY.cmd index f85ea2b..df7fa51 100644 --- a/kopia_backup/kopia_cli_deploy_win/DEPLOY.cmd +++ b/kopia_backup/kopia_cli_deploy_win/DEPLOY.cmd @@ -13,10 +13,6 @@ if %errorLevel% == 0 ( 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 @@ -28,11 +24,15 @@ if exist "C:\Kopia\kopia_backup_scipt.ps1" ( ) echo - copying files to C:\Kopia +robocopy "%~dp0\" "C:\Kopia" "kopia.exe" /NDL /NJH /NJS 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. +echo - adding C:\Kopia to PATH +setx /M PATH "%PATH%;C:\Kopia" + 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 diff --git a/kopia_backup/kopia_cli_deploy_win/kopia_backup_scipt.ps1 b/kopia_backup/kopia_cli_deploy_win/kopia_backup_scipt.ps1 index 84fe3a3..752e7ec 100644 --- a/kopia_backup/kopia_cli_deploy_win/kopia_backup_scipt.ps1 +++ b/kopia_backup/kopia_cli_deploy_win/kopia_backup_scipt.ps1 @@ -1,5 +1,5 @@ -# Before using this script, initiate the repo -# kopia repo create filesystem --path C:\kopia_repo --password aaa +# Before using this script, create a repo +# kopia repo create filesystem --path C:\kopia_repo --password aaa --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs # useful commands: # - kopia repo connect filesystem --path C:\kopia_repo -p aaa @@ -18,20 +18,22 @@ # - [array]$BACKUP_THIS = 'C:\Test','C:\Test2','C:\Test3' $REPOSITORY_PATH = 'C:\kopia_repo' -$KOPIA_PASSWORD='aaa' +$KOPIA_PASSWORD = 'aaa' [array]$BACKUP_THIS = 'C:\Test' $USE_SHADOW_COPY = $false # ---------------------------------------------------------------------------- -kopia repository connect filesystem --path $REPOSITORY_PATH --password $KOPIA_PASSWORD --enable-actions +kopia repository connect filesystem --path $REPOSITORY_PATH --password $KOPIA_PASSWORD --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=8 --keep-daily=14 --keep-hourly=0 --keep-latest=3 --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs 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 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 + kopia snapshot create $path --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs } -kopia repository disconnect +kopia repository disconnect --file-log-level=info --log-dir=C:\Kopia\Kopia_Logs diff --git a/kopia_backup/kopia_server_deploy_win/DEPLOY.cmd b/kopia_backup/kopia_server_deploy_win/DEPLOY.cmd deleted file mode 100644 index a32d801..0000000 --- a/kopia_backup/kopia_server_deploy_win/DEPLOY.cmd +++ /dev/null @@ -1,54 +0,0 @@ -@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 - copying link to Desktop -robocopy "%~dp0\" "%USERPROFILE%\Desktop" "Kopia.url" /NDL /NJH /NJS - -echo. -echo -------------------------------------------------------------- -echo. -echo DEPLOYMENT DONE -echo KOPIA SERVER CAN NOW BE FIND AT WEB PAGE: localhost:51515 -echo A LINK SHOULD BE ON YOUR DESKTOP -echo. -pause diff --git a/kopia_backup/kopia_server_deploy_win/Kopia.url b/kopia_backup/kopia_server_deploy_win/Kopia.url deleted file mode 100644 index fbd84cb..0000000 --- a/kopia_backup/kopia_server_deploy_win/Kopia.url +++ /dev/null @@ -1,6 +0,0 @@ -[InternetShortcut] -URL=http://localhost:51515/ -IDList= -HotKey=0 -[{000214A0-0000-0000-C000-000000000046}] -Prop3=19,2 diff --git a/kopia_backup/kopia_server_deploy_win/kopia.exe b/kopia_backup/kopia_server_deploy_win/kopia.exe deleted file mode 100644 index 3878b58..0000000 Binary files a/kopia_backup/kopia_server_deploy_win/kopia.exe and /dev/null differ diff --git a/kopia_backup/kopia_server_deploy_win/kopia_server_backup_start.xml b/kopia_backup/kopia_server_deploy_win/kopia_server_backup_start.xml deleted file mode 100644 index 363ca01..0000000 Binary files a/kopia_backup/kopia_server_deploy_win/kopia_server_backup_start.xml and /dev/null differ diff --git a/kopia_backup/kopia_server_deploy_win/kopia_server_start.cmd b/kopia_backup/kopia_server_deploy_win/kopia_server_start.cmd deleted file mode 100644 index 5c385d4..0000000 --- a/kopia_backup/kopia_server_deploy_win/kopia_server_start.cmd +++ /dev/null @@ -1,2 +0,0 @@ -chdir /d C:\Kopia -start /B kopia server start --insecure --address=127.0.0.1:51515 --server-username=admin --server-password=aaa diff --git a/kopia_backup/kopia_server_deploy_win/win_vss_after.ps1 b/kopia_backup/kopia_server_deploy_win/win_vss_after.ps1 deleted file mode 100644 index 01c9fb8..0000000 --- a/kopia_backup/kopia_server_deploy_win/win_vss_after.ps1 +++ /dev/null @@ -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 - } -} diff --git a/kopia_backup/kopia_server_deploy_win/win_vss_before.ps1 b/kopia_backup/kopia_server_deploy_win/win_vss_before.ps1 deleted file mode 100644 index e3692b1..0000000 --- a/kopia_backup/kopia_server_deploy_win/win_vss_before.ps1 +++ /dev/null @@ -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}" diff --git a/kopia_backup/readme.md b/kopia_backup/readme.md index 4843d07..2c3c536 100644 --- a/kopia_backup/readme.md +++ b/kopia_backup/readme.md @@ -68,37 +68,34 @@ if planning serious use. * Backups are stored in a **repository** that needs to be created first, and is always encrypted. * Before any action, Kopia needs to be **connected to a repo** as repos store most of - the settings and commands are executed in their context. -* **Snapshots**, apart from the typical meaning, is the term used by Kopia for - targets(paths) that are being backed up. -* **Policy** is a term used to define behavior of the backup/repo, - like backups retention, what to ignore, logging, scheduling(server/UI), - actions before and after backup,... + the settings(policies), and commands are executed in their context. + Multiple machines can be connected simultaneously. +* **Snapshots**, is the term used by Kopia for targets(paths) that are being backed up. +* **Policy** - settings for repo/backup behaviour, stuff like backups retention, + what to ignore, logging, scheduling(server/UI), actions before and after backup,... * **Policies** are stored inside a repo and can apply at various levels and can **inherit** from each other - **Global** policy, the default that comes predefined during repo creation, can be edited like any other. - - Per user policy, per machine policy. + - Per user@machine policy - Snapshot level policy, only applying for that one path. * **Maintenance** is automatic. -* During snapshots Kopia uses local **cache**, location varies depending on the OS. - Default max size is 5GB, but it gets swept periodically every few minutes.
- Useful commands are `kopia cache info` and `kopia cache clear` * **Retention** of backups - [here's](https://kopia.discourse.group/t/trying-to-understand-retention-policies/164/4) how it works under the hood.
- The core concept that it is the **most recent** item of a time-group thats counted - first towards whats kept should be understood. Or it can surprise that for example - `keep-annual=2` is worthless in january, as the **most recent** two different years - are backups so close to each other. * **Restore** from backups is most easily done by mounting a snapshot.
Web GUI versions have button for it, cli version can do `sudo kopia mount all /mnt/temp &` * **Tasks** section in gui gets wiped when Kopia closes, info on snapshots run history and duration then has to be find in logs -* **Logs** rotate with max age 30 days or max 1000 log files, 5000 content log files +* **Logs** rotate with max age 30 days or max 1000 log files, 5000 content log files
+ Useful to search in cli-logs are the terms `kopia/server snapshotting` and + `kopia/server finished` * [Compression](https://kopia.io/docs/advanced/compression/) is good and - should be set before backup starts.`zstd-fastest` is my go-to. If backups - feel slow `s2-default` is less cpu heavy but with worse compression.
+ should be set before backup starts. My go-to is `zstd-fastest`. If backups + feel slow `s2-default` is less cpu heavy but with worse compression. Useful command: `kopia content stats` +* During snapshots Kopia uses local **cache**, location varies depending on the OS. + Default max size is 5GB, but it gets swept periodically every few minutes.
+ Useful commands are `kopia cache info` and `kopia cache clear` * .. # Kopia in Linux @@ -106,7 +103,7 @@ if planning serious use. ![list_snapshots_cli](https://i.imgur.com/lQ8W5yh.png) cli version of kopia will be used to periodically backup to a mounted network storage.
-The backup script will be executed using systemd-timers for scheduling. +The backup script will be periodicly executed using systemd-timers. ### Install Kopia @@ -284,9 +281,11 @@ But since we are here... * [Download latest release](https://github.com/kopia/kopia/releases) * Extract it somewhere, lets say `C:\Kopia` * Run it, click through repo creation -* select what to backup +* set global policy + * recommend setting compression, `zstd-fastest` * set schedule - * recommend setting compression, at least s2-default + * retention rules +* select what to backup * Right click tray icon and set to "Launch at startup" * done @@ -312,7 +311,11 @@ Kopia always running in the background, but also webgui to manage it in. that's where credentials are set, default: `admin // aaa` * Visit in browser `localhost:51515` * Setup new repo through webgui. -* Setup what to backup, compression and schedule. +* set global policy + * recommend setting compression, `zstd-fastest` + * set schedule + * retention rules +* Select what to backup. Kopia should now run on boot and be easy to manage through web GUI.
Be it creating backup jobs, mounting old snapshots to restore files, @@ -333,14 +336,14 @@ Also use of [nssm](https://nssm.cc/) is popular. ![windows_scoop_install_kopia](https://i.imgur.com/UPZFImh.png) -Kopia binary is copied in to `C:\Windows\System32\` +Kopia binary is copied in to `C:\Kopia` along with other files. and a scheduled task is imported that executes a powershell script `C:\Kopia\kopia_backup_scipt.ps1` at 21:19. The script executes few kopia commands - connects to a repo, backs up stuff, and disconnects. -Bit more hands on than having a gui, but once setup one can easily get by with -two commands: `kopia snap list -all` and `kopia mount all K:`
+Bit more hands on than having a gui, but for daily use one can easily get by with +the commands: `kopia snap list -all` and `kopia mount all K:`
Note that mount command should be executed in non admin terminal. Weird windows thing. @@ -351,17 +354,18 @@ so that VSS snapshots can be used. delete everything except `kopia_cli_deploy_win` folder. * Run `DEPLOY.cmd`, it will: * Removes powershell scripts restriction. - * kopies kopia.exe in to `C:\Windows\System32` * Creates folder `C:\Kopia` and kopies there
- `kopia_backup_scipt.ps1` and the VSS ps1 before and after files. + `kopia.exe`, `kopia_backup_scipt.ps1` and the VSS ps1 before and after files. + * Adds `C:\Kopia` to the system env variable PATH. * imports a task schedule * Read `kopia_backup_scipt.ps1` and follow the instructions there.
- Which should be to just to create repo before running the script.
- `kopia repo create filesystem --path C:\kopia_repo --password aaa` + Which should be to just to create repo before running the script. * edit the scheduled task to the prefered time, default is daily at 21:19 * run scheduled task manually * check if it worked - * `kopia snap list --all` + * `kopia snap list --all` + +The script is set to save logs in to `C:\Kopia`. ### VSS snapshots