2023-01-21 20:48:29 +00:00
|
|
|
# Kopia
|
|
|
|
|
|
|
|
###### guide-by-example
|
|
|
|
|
2024-04-21 20:27:51 +00:00
|
|
|
*Last update april 2024 kopia v0.17.0*
|
|
|
|
|
2023-01-21 20:48:29 +00:00
|
|
|
![logo](https://i.imgur.com/A2mosM6.png)
|
|
|
|
|
2023-09-04 11:03:32 +00:00
|
|
|
# Content
|
|
|
|
|
2023-09-05 18:02:52 +00:00
|
|
|
* [Kopia in Linux](#Kopia-in-Linux)
|
|
|
|
* [Kopia in Windows](#Kopia-in-Windows)
|
2023-09-04 10:29:42 +00:00
|
|
|
* [Kopia in Docker](#Kopia-in-Docker)
|
2023-09-12 20:58:12 +00:00
|
|
|
* [Kopia backup to Cloud](#Kopia-backup-to-Cloud)
|
2023-01-21 20:48:29 +00:00
|
|
|
|
|
|
|
# Purpose & Overview
|
|
|
|
|
|
|
|
Backups.
|
|
|
|
|
|
|
|
* [Official site](https://kopia.io/)
|
2023-09-04 10:29:42 +00:00
|
|
|
* [Official Forum](https://kopia.discourse.group/)
|
2023-01-21 20:48:29 +00:00
|
|
|
* [Github](https://github.com/kopia/kopia)
|
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
Kopia is a new open source backup utility with basically **all** modern features.</br>
|
2023-01-21 20:48:29 +00:00
|
|
|
Cross-platform, deduplication, encryption, compression, multithreaded speed,
|
2023-08-31 18:16:44 +00:00
|
|
|
native cloud storage support, repository replication, snapshots mounting,
|
2023-09-04 18:25:32 +00:00
|
|
|
GUI version, server version,...
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
Written in golang.<br>
|
2023-09-04 18:25:32 +00:00
|
|
|
Embedded webGUI for server mode is done in React. KopiaUI comes packaged with electron.
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
### Ways to use Kopia
|
2023-08-31 18:16:44 +00:00
|
|
|
|
|
|
|
* **cli** - Command line.<br>
|
2024-04-21 20:27:51 +00:00
|
|
|
You execute kopia binary passing some commands, it does stuff, done.<br>
|
2023-09-04 10:29:42 +00:00
|
|
|
Deployment requires extra work - scripts with configs, scheduling.
|
|
|
|
* **KopiaUI** - GUI version.<br>
|
2023-09-15 14:47:07 +00:00
|
|
|
Kopia that comes packaged with electron for GUI to provide the feel of a standalone desktop app.<br>
|
2023-09-04 10:29:42 +00:00
|
|
|
Good for simple deployment where average user just wants to backup stuff.<br>
|
2024-04-21 20:27:51 +00:00
|
|
|
Benefits over cli is much easier setup, management.<br>
|
2023-09-04 10:29:42 +00:00
|
|
|
Drawback is that it runs under one user and only when that user is logged in.
|
2023-09-15 14:47:07 +00:00
|
|
|
* **Kopia Server** - kopia binary runs in a server mode.<br>
|
|
|
|
Runs in the background, now with its web server answering at url: `localhost:51515`<br>
|
|
|
|
Web GUI at the url makes the management easy so it can replace KopiaUI.<br>
|
2024-04-21 20:27:51 +00:00
|
|
|
But the intended purpose of the server mode is that Kopia instance can now serve
|
2023-09-15 14:47:07 +00:00
|
|
|
as a centralized repository for other machines that run their Kopia instances
|
2024-04-21 20:27:51 +00:00
|
|
|
and select server's url as a repository where to backup.<br>
|
2023-09-15 14:47:07 +00:00
|
|
|
Deployment requires extra work similar to cli, but actual use is through web GUI.
|
2024-04-21 20:27:51 +00:00
|
|
|
* **Kopia in Docker** - Kopia Server running as a docker container<br>
|
2023-09-04 10:29:42 +00:00
|
|
|
Can fulfill two needs:
|
2023-09-15 14:47:07 +00:00
|
|
|
* A centralized Kopia repository where other machines on the network,
|
|
|
|
that also use Kopia, backup their data.
|
2023-09-04 10:29:42 +00:00
|
|
|
* Backup docker-host stuff to a cloud or a mounted network storage.
|
|
|
|
Managed through webgui instead of cli.
|
|
|
|
|
|
|
|
![repo_first](https://i.imgur.com/rbqhmzZ.png)
|
|
|
|
|
|
|
|
# Some aspects of Kopia
|
2023-08-31 18:16:44 +00:00
|
|
|
|
|
|
|
[Official Getting Started Guide](https://kopia.io/docs/getting-started/)<br>
|
2024-04-21 18:18:29 +00:00
|
|
|
[Features](https://kopia.io/docs/features/)<br>
|
2023-09-07 22:28:11 +00:00
|
|
|
[Advanced Topics](https://kopia.io/docs/advanced/)
|
|
|
|
|
|
|
|
The above linked documentation is well written and worth a look
|
|
|
|
if planning serious use.
|
2023-08-31 18:16:44 +00:00
|
|
|
|
|
|
|
* Kopia is a single ~35MB binary file.
|
|
|
|
* Backups are stored in a **repository** that needs to be created first,
|
2023-09-07 22:28:11 +00:00
|
|
|
and is always encrypted.
|
|
|
|
* Before any action, Kopia needs to be **connected to a repo** as repos store most of
|
2023-09-11 20:14:36 +00:00
|
|
|
the settings(policies), and commands are executed in their context.
|
|
|
|
Multiple machines can be connected simultaneously.
|
2024-06-02 22:16:50 +00:00
|
|
|
* **Snapshots** are the backups created by kopia, stored in a repository.
|
2023-09-11 20:14:36 +00:00
|
|
|
* **Policy** - settings for repo/backup behaviour, stuff like backups retention,
|
|
|
|
what to ignore, logging, scheduling(server/UI), actions before and after backup,...
|
2023-08-31 18:16:44 +00:00
|
|
|
* **Policies** are stored inside a repo and can apply at various levels and
|
2023-09-04 10:29:42 +00:00
|
|
|
can **inherit** from each other
|
|
|
|
- **Global** policy, the default that comes predefined during repo creation,
|
|
|
|
can be edited like any other.
|
2023-09-11 20:14:36 +00:00
|
|
|
- Per user@machine policy
|
2023-09-04 10:29:42 +00:00
|
|
|
- Snapshot level policy, only applying for that one path.
|
2023-09-07 22:28:11 +00:00
|
|
|
* **Maintenance** is automatic.
|
2023-09-04 18:25:32 +00:00
|
|
|
* **Retention** of backups - [here's](https://kopia.discourse.group/t/trying-to-understand-retention-policies/164/4)
|
|
|
|
how it works under the hood.<br>
|
2023-09-05 15:05:34 +00:00
|
|
|
* **Restore** from backups is most easily done by mounting a snapshot.<br>
|
|
|
|
Web GUI versions have button for it, cli version can do `sudo kopia mount all /mnt/temp &`
|
2023-09-05 19:08:04 +00:00
|
|
|
* **Tasks** section in gui gets wiped when Kopia closes, info on snapshots run
|
|
|
|
history and duration then has to be find in logs
|
2024-04-21 18:18:29 +00:00
|
|
|
* **Logs** are creted on every execution of kopia binary.<br>
|
|
|
|
They rotate by default with max age 30 days, but still can grow hundreds of MB.
|
2023-09-07 22:28:11 +00:00
|
|
|
* [Compression](https://kopia.io/docs/advanced/compression/) is good and
|
2023-09-11 20:14:36 +00:00
|
|
|
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.
|
2023-09-07 22:28:11 +00:00
|
|
|
Useful command: `kopia content stats`
|
2023-09-11 20:14:36 +00:00
|
|
|
* During snapshots Kopia uses local **cache**, location varies depending on the OS.
|
2024-04-21 18:18:29 +00:00
|
|
|
Default max size is 5GB. Cache gets swept periodically every few minutes.<br>
|
2024-04-21 20:27:51 +00:00
|
|
|
Useful commands are `kopia cache info` and `kopia cache clear`.<br>
|
|
|
|
Increase [considerably the max cache size](https://github.com/kopia/kopia/issues/3059#issuecomment-1663479603)
|
2024-05-11 07:44:39 +00:00
|
|
|
if planning to use cloud storage, as the maintenance could eat into egress cost
|
2024-04-21 18:18:29 +00:00
|
|
|
when kopia redownloads files.
|
|
|
|
* ...
|
|
|
|
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-05 18:02:52 +00:00
|
|
|
# Kopia in Linux
|
2023-01-29 12:30:34 +00:00
|
|
|
|
2023-09-04 11:03:32 +00:00
|
|
|
![list_snapshots_cli](https://i.imgur.com/lQ8W5yh.png)
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-15 14:03:20 +00:00
|
|
|
A script will be periodically executing cli version of kopia to connect to a repository,
|
|
|
|
execute backup, and disconnect.<br>
|
2023-09-26 21:07:39 +00:00
|
|
|
Systemd-timers are used to schedule execution of the script.
|
2023-09-15 14:03:20 +00:00
|
|
|
The repository is created on a network share, also mounted on boot using systemd.
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
### Install Kopia
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
For arch linux, kopia is on AUR `yay kopia-bin`
|
2023-01-29 12:30:34 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
### The initial steps and general use commands
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-08-31 18:16:44 +00:00
|
|
|
* **repo creation**
|
|
|
|
|
2023-09-05 15:05:34 +00:00
|
|
|
|
2023-08-31 18:16:44 +00:00
|
|
|
`sudo kopia repo create filesystem --path /mnt/mirror/KOPIA/docker_host_kopia`<br>
|
|
|
|
`sudo kopia repo connect filesystem --path /mnt/mirror/KOPIA/docker_host_kopia`<br>
|
2023-09-05 15:05:34 +00:00
|
|
|
`sudo kopia repo status`
|
|
|
|
|
|
|
|
If the path used during creation does not exists, kopia will create it in full.<br>
|
|
|
|
After creation the repo is connected, so connnect command is just demonstration.
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-01-29 12:30:34 +00:00
|
|
|
* **the policy info and change**
|
|
|
|
|
|
|
|
`sudo kopia policy list`<br>
|
2023-09-07 22:28:11 +00:00
|
|
|
`sudo kopia policy show --global`<br>
|
2024-04-21 18:18:29 +00:00
|
|
|
`sudo 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`<br>
|
2023-01-29 12:30:34 +00:00
|
|
|
|
2023-09-05 15:05:34 +00:00
|
|
|
* **manual backup run**
|
2023-01-24 07:52:43 +00:00
|
|
|
|
2023-01-29 12:30:34 +00:00
|
|
|
`sudo kopia snapshot create /home/spravca/docker /etc`<br>
|
|
|
|
`sudo kopia snapshot list`<br>
|
2023-01-24 07:52:43 +00:00
|
|
|
|
2023-09-05 15:05:34 +00:00
|
|
|
Since the connection exists with a repo,
|
|
|
|
all that is needed is target that should be backed up.
|
|
|
|
|
|
|
|
* **mounting backups**
|
2023-01-24 07:52:43 +00:00
|
|
|
|
2023-08-31 18:16:44 +00:00
|
|
|
`sudo kopia mount all /mnt/tmp &` - mounts all snapshots<br>
|
|
|
|
`sudo kopia snapshot list`<br>
|
2023-01-29 12:30:34 +00:00
|
|
|
`sudo kopia mount k7e2b0a503edd7604ff61c68655cd5ad7 /mnt/tmp &`<br>
|
|
|
|
`sudo umount /mnt/tmp`<br>
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-08-31 18:16:44 +00:00
|
|
|
### The backup script
|
2023-01-24 07:52:43 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
In linux, passing multiple paths separated by space seems to work fine.<br>
|
|
|
|
So both `/home` and `/etc` are set to be backed up.
|
|
|
|
|
2023-01-24 07:52:43 +00:00
|
|
|
`/opt/kopia-backup-home-etc.sh`
|
2023-01-29 12:30:34 +00:00
|
|
|
```bash
|
2023-01-24 07:52:43 +00:00
|
|
|
#!/bin/bash
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2024-04-21 18:18:29 +00:00
|
|
|
# v0.2
|
2023-09-04 10:29:42 +00:00
|
|
|
# initialize repository
|
|
|
|
# sudo kopia repo create filesystem --path /mnt/mirror/KOPIA/docker_host_kopia
|
2023-09-16 09:32:36 +00:00
|
|
|
# for cloud like backblaze
|
|
|
|
# sudo kopia repository create b2 --bucket=rakanishu --key-id=001496285081a7e0000000003 --key=K0016L8FAMRp/F+6ckbXIYpP0UgTky0
|
|
|
|
# sudo kopia repository connect b2 --bucket=rakanishu --key-id=001496285081a7e0000000003 --key=K0016L8FAMRp/F+6ckbXIYpP0UgTky0
|
2023-09-04 10:29:42 +00:00
|
|
|
# adjust global policy
|
2024-04-21 18:18:29 +00:00
|
|
|
# sudo 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
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-16 10:05:58 +00:00
|
|
|
REPOSITORY_PATH='/mnt/mirror/KOPIA/docker_host_kopia'
|
2023-01-24 07:52:43 +00:00
|
|
|
BACKUP_THIS='/home /etc'
|
2023-09-16 09:32:36 +00:00
|
|
|
export KOPIA_PASSWORD='aaa'
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-16 09:32:36 +00:00
|
|
|
kopia repository connect filesystem --path $REPOSITORY_PATH
|
2023-01-24 07:52:43 +00:00
|
|
|
kopia snapshot create $BACKUP_THIS
|
|
|
|
kopia repository disconnect
|
2023-09-16 09:32:36 +00:00
|
|
|
|
2024-04-21 18:18:29 +00:00
|
|
|
# -------------- ERROR EXIT CODES --------------
|
2023-09-16 10:13:14 +00:00
|
|
|
# kopia does not interupts its run with an error if target or repository are missing
|
2024-04-21 18:18:29 +00:00
|
|
|
# this makes systemd OnSuccess OnFailure not behaving as one might expect
|
|
|
|
# below are checks for paths, that result in immediate error exit code if they do not exist
|
|
|
|
# they are at the end because some backup might get done even if another is missing something
|
2023-09-16 12:27:24 +00:00
|
|
|
# we just want the error exit code
|
2023-09-16 10:13:14 +00:00
|
|
|
|
2023-09-16 09:32:36 +00:00
|
|
|
IFS=' ' read -ra paths <<< "$BACKUP_THIS"
|
|
|
|
for path in "${paths[@]}"; do
|
|
|
|
if [ ! -e "$path" ]; then
|
2023-09-16 10:30:15 +00:00
|
|
|
echo "ERROR: Backup target '$path' does not exist."
|
2023-09-16 09:32:36 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-09-16 09:52:15 +00:00
|
|
|
if [ ! -d "$REPOSITORY_PATH" ]; then
|
2023-09-16 10:30:15 +00:00
|
|
|
echo "ERROR: Directory '$REPOSITORY_PATH' does not exist."
|
2023-09-16 09:52:15 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-01-24 07:52:43 +00:00
|
|
|
```
|
2023-09-04 10:29:42 +00:00
|
|
|
|
2023-08-31 18:16:44 +00:00
|
|
|
make the script executable<br>
|
|
|
|
`sudo chmod +x /opt/kopia-backup-home-etc.sh`
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-02-07 17:13:11 +00:00
|
|
|
### Scheduled backups using systemd
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-01-29 21:21:19 +00:00
|
|
|
Usually cron is used, but systemd provides better logging and control,
|
2023-01-29 12:50:28 +00:00
|
|
|
so better get used to using it.<br>
|
|
|
|
[Heres](https://github.com/kopia/kopia/issues/2685#issuecomment-1384524828)
|
2023-02-07 17:13:11 +00:00
|
|
|
some discussion on unit files.<br>
|
2023-08-31 18:16:44 +00:00
|
|
|
[ntfy](https://github.com/binwiederhier/ntfy) can be used for notifications,
|
2023-01-29 21:21:19 +00:00
|
|
|
more info [here](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/gotify-ntfy-signal#linux-systemd-unit-file-service)
|
|
|
|
|
2023-08-31 18:16:44 +00:00
|
|
|
* `sudo micro /etc/systemd/system/kopia-home-etc.service`
|
|
|
|
|
2023-01-29 12:30:34 +00:00
|
|
|
```kopia-home-etc.service```
|
|
|
|
```ini
|
|
|
|
[Unit]
|
|
|
|
Description=kopia backup
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
|
|
|
ConditionACPower=true
|
2023-02-07 17:13:11 +00:00
|
|
|
# OnFailure=ntfy@failure-%p.service
|
2023-01-29 21:21:19 +00:00
|
|
|
# OnSuccess=ntfy@success-%p.service
|
2023-01-29 12:30:34 +00:00
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
|
|
|
|
# Lower CPU and I/O priority.
|
|
|
|
Nice=19
|
|
|
|
CPUSchedulingPolicy=batch
|
|
|
|
IOSchedulingPriority=7
|
|
|
|
|
|
|
|
IPAccounting=true
|
|
|
|
PrivateTmp=true
|
|
|
|
Environment="HOME=/root"
|
|
|
|
|
2023-01-29 21:21:19 +00:00
|
|
|
ExecStart=/opt/kopia-backup-home-etc.sh
|
2023-01-29 12:30:34 +00:00
|
|
|
```
|
|
|
|
|
2023-08-31 18:16:44 +00:00
|
|
|
* `sudo micro /etc/systemd/system/kopia-home-etc.timer`
|
2023-01-29 12:30:34 +00:00
|
|
|
|
|
|
|
```kopia-home-etc.timer```
|
2023-02-07 17:51:43 +00:00
|
|
|
```ini
|
2023-01-29 12:30:34 +00:00
|
|
|
[Unit]
|
|
|
|
Description=Run kopia backup
|
|
|
|
|
|
|
|
[Timer]
|
2023-01-29 21:21:19 +00:00
|
|
|
OnCalendar=*-*-* 02:00:00
|
|
|
|
RandomizedDelaySec=10min
|
2023-01-29 12:30:34 +00:00
|
|
|
Persistent=true
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=timers.target
|
|
|
|
```
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-08-31 18:16:44 +00:00
|
|
|
* `sudo systemctl enable --now kopia-home-etc.timer`
|
|
|
|
* `systemctl status kopia-home-etc.timer`
|
|
|
|
* `journalctl -u kopia-home-etc.timer` - see history
|
|
|
|
|
2023-09-16 10:27:03 +00:00
|
|
|
### Troubleshooting
|
|
|
|
|
|
|
|
To see logs of last Kopia runs done by systemd
|
|
|
|
|
|
|
|
* `sudo journalctl -ru kopia-home-etc.service`
|
|
|
|
* `sudo journalctl -xru kopia-home-etc.service`
|
2023-09-04 10:29:42 +00:00
|
|
|
|
2023-09-26 21:07:39 +00:00
|
|
|
![journaclt_output](https://i.imgur.com/46XIFFO.png)
|
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
<details>
|
|
|
|
<summary><h3>Mounting network storage using systemd</h3></summary>
|
2023-01-24 07:52:43 +00:00
|
|
|
|
2023-02-07 17:13:11 +00:00
|
|
|
* files are placed in `/etc/systemd/system`
|
2023-01-24 07:52:43 +00:00
|
|
|
* the name of mount and automount files MUST correspond with the path<br>
|
2023-02-07 17:13:11 +00:00
|
|
|
replacing `/` with a `-`,
|
|
|
|
but otherwise it must be the mounting path in the name
|
|
|
|
* for mounting that does not fail on boot if there are network issues,
|
2023-01-29 12:50:28 +00:00
|
|
|
and mounts the target only on request - enable `automount` file,
|
|
|
|
not `mount` file, so:<br>
|
2023-01-24 07:52:43 +00:00
|
|
|
`sudo systemctl enable mnt-mirror.automount`
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-01-24 07:52:43 +00:00
|
|
|
`mnt-mirror.mount`
|
|
|
|
```ini
|
|
|
|
[Unit]
|
|
|
|
Description=3TB truenas mirror mount
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-01-24 07:52:43 +00:00
|
|
|
[Mount]
|
|
|
|
What=//10.0.19.11/Mirror
|
|
|
|
Where=/mnt/mirror
|
|
|
|
Type=cifs
|
|
|
|
Options=rw,username=kopia,password=aaa,file_mode=0644,dir_mode=0755,uid=1000,gid=1000
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-01-24 07:52:43 +00:00
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
|
|
|
|
|
|
|
`mnt-mirror.automount`
|
|
|
|
```ini
|
|
|
|
[Unit]
|
|
|
|
Description=3TB truenas mirror mount
|
|
|
|
|
|
|
|
[Automount]
|
|
|
|
Where=/mnt/mirror
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
</details>
|
|
|
|
|
|
|
|
---
|
|
|
|
---
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-05 18:02:52 +00:00
|
|
|
# Kopia in Windows
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-09-15 14:03:20 +00:00
|
|
|
![windows_snapshot_history_gui](https://i.imgur.com/MI16Zp1.png)
|
2023-03-05 09:50:50 +00:00
|
|
|
|
2023-09-05 19:51:58 +00:00
|
|
|
## KopiaUI in Windows
|
2023-09-05 18:43:03 +00:00
|
|
|
|
2023-09-07 22:28:11 +00:00
|
|
|
KopiaUI does not really need a guide. It's simple and just works for normal use.<br>
|
|
|
|
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
|
2023-09-11 20:14:36 +00:00
|
|
|
* set global policy
|
|
|
|
* recommend setting compression, `zstd-fastest`
|
2023-09-07 22:28:11 +00:00
|
|
|
* set schedule
|
2023-09-11 20:14:36 +00:00
|
|
|
* retention rules
|
|
|
|
* select what to backup
|
2023-09-07 22:28:11 +00:00
|
|
|
* Right click tray icon and set to "Launch at startup"
|
|
|
|
* done
|
2023-09-05 18:43:03 +00:00
|
|
|
|
2023-09-07 22:28:11 +00:00
|
|
|
It will now start on users login, and executes at set schedule.
|
|
|
|
|
|
|
|
While KopiaUI seems like the way to go because of the simple deployment and
|
|
|
|
use, it has a drawback. The scheduled backups works only when user is logged in.
|
|
|
|
Which for many deployments feel like it introduces unnecessary uncertainty,
|
|
|
|
or is not even viable when servers often run with no user logged in.
|
2023-09-05 18:43:03 +00:00
|
|
|
|
|
|
|
## Kopia Server in Windows
|
|
|
|
|
2023-09-15 15:04:45 +00:00
|
|
|
My go-to for windows use because it offers gui for easier managment and
|
|
|
|
the reliability of always running in the background as a service.
|
|
|
|
|
|
|
|
This deployment does not make use of the main Kopia Server feature,
|
|
|
|
to be a repository for other machines running Kopiam, just local deployment.
|
|
|
|
Few edits of `kopia_server_start.cmd` can make it happen though.
|
2023-08-31 18:16:44 +00:00
|
|
|
|
2023-09-04 18:25:32 +00:00
|
|
|
* [Download this repo](https://github.com/DoTheEvo/selfhosted-apps-docker/archive/refs/heads/master.zip),
|
2023-09-06 22:29:42 +00:00
|
|
|
delete everything except `kopia_backup/kopia_server_deploy_service_win` folder.
|
2023-09-06 22:18:40 +00:00
|
|
|
* Run `DEPLOY.cmd` as admin, it will:
|
2023-08-31 18:16:44 +00:00
|
|
|
* Removes powershell scripts restriction.
|
2023-09-06 22:18:40 +00:00
|
|
|
* Creates folder `C:\Kopia` and copies files there.
|
2023-09-06 22:29:42 +00:00
|
|
|
* Uses [shawl](https://github.com/mtkennerly/shawl) to create Kopia service.
|
2023-09-06 22:18:40 +00:00
|
|
|
* Places `kopia.url` on the current user's desktop.
|
|
|
|
* One should check content of `C:\Kopia\kopia_server_start.cmd`<br>
|
2023-09-06 22:29:42 +00:00
|
|
|
that's where credentials are set, default: `admin // aaa`
|
2023-09-05 19:51:58 +00:00
|
|
|
* Visit in browser `localhost:51515`
|
|
|
|
* Setup new repo through webgui.
|
2023-09-11 20:14:36 +00:00
|
|
|
* set global policy
|
|
|
|
* recommend setting compression, `zstd-fastest`
|
|
|
|
* set schedule
|
|
|
|
* retention rules
|
|
|
|
* Select what to backup.
|
2023-08-31 18:16:44 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
Kopia should now run on boot and be easy to manage through web GUI.<br>
|
2023-09-05 19:08:04 +00:00
|
|
|
Be it creating backup jobs, mounting old snapshots to restore files,
|
|
|
|
or just looking around if all works as it should.
|
2023-09-04 10:29:42 +00:00
|
|
|
|
2023-09-06 22:18:40 +00:00
|
|
|
All relevant files are in `C:\Kopia`, from binaries, `repository.config`, to logs.
|
2023-09-04 10:29:42 +00:00
|
|
|
|
2023-09-06 22:18:40 +00:00
|
|
|
Before shawl, task scheduler was used.<br>
|
|
|
|
This [matushorvath/Kopia as Windows Service](https://gist.github.com/matushorvath/dd7148c201ceae03ddebc1b4bbef4d20)
|
|
|
|
guide helped move beyond that. It contains more info if one would want to
|
|
|
|
actually run as server repository for other machines.<br>
|
|
|
|
Also use of [nssm](https://nssm.cc/) is popular.
|
2023-08-31 18:16:44 +00:00
|
|
|
|
2023-09-05 18:43:03 +00:00
|
|
|
## Kopia cli in Windows
|
2023-08-31 18:16:44 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
![windows_scoop_install_kopia](https://i.imgur.com/UPZFImh.png)
|
2023-08-31 18:16:44 +00:00
|
|
|
|
2024-04-21 18:18:29 +00:00
|
|
|
At the moment **cli is the only way to use VSS snapshots**.
|
|
|
|
|
2023-09-12 19:09:07 +00:00
|
|
|
All relevant files are in `C:\Kopia`, from binaries, `repository.config`, to logs.
|
|
|
|
A scheduled task is imported that executes a powershell script
|
2023-09-05 19:51:58 +00:00
|
|
|
`C:\Kopia\kopia_backup_scipt.ps1` at 21:19.
|
2023-09-12 19:09:07 +00:00
|
|
|
The script connects to a set repo and backup set targets.
|
2023-09-05 19:51:58 +00:00
|
|
|
|
2023-09-12 19:09:07 +00:00
|
|
|
This approach is 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:`<br>
|
2024-04-21 18:18:29 +00:00
|
|
|
Note that if mount command is not working, try executing it in non admin terminal. Weird
|
|
|
|
windows thing. Or you need to enable/install `WebClient` service.
|
2023-09-04 10:29:42 +00:00
|
|
|
|
2023-09-04 18:25:32 +00:00
|
|
|
* [Download this repo](https://github.com/DoTheEvo/selfhosted-apps-docker/archive/refs/heads/master.zip),
|
2023-09-05 19:08:04 +00:00
|
|
|
delete everything except `kopia_cli_deploy_win` folder.
|
2023-09-12 19:09:07 +00:00
|
|
|
* Run `DEPLOY.cmd`
|
2023-08-31 18:16:44 +00:00
|
|
|
* Removes powershell scripts restriction.
|
|
|
|
* Creates folder `C:\Kopia` and kopies there<br>
|
2024-04-21 18:18:29 +00:00
|
|
|
`kopia.exe`, `kopia_backup_scipt.ps1`.
|
2023-09-11 20:14:36 +00:00
|
|
|
* Adds `C:\Kopia` to the system env variable PATH.
|
2024-04-21 18:18:29 +00:00
|
|
|
* imports a scheduled task.
|
2023-09-05 19:08:04 +00:00
|
|
|
* Read `kopia_backup_scipt.ps1` and follow the instructions there.<br>
|
2023-09-11 20:14:36 +00:00
|
|
|
Which should be to just to create repo before running the script.
|
2023-09-04 10:29:42 +00:00
|
|
|
* edit the scheduled task to the prefered time, default is daily at 21:19
|
|
|
|
* run scheduled task manually
|
|
|
|
* check if it worked
|
2024-04-21 18:18:29 +00:00
|
|
|
* `kopia repo status`
|
2023-09-11 20:14:36 +00:00
|
|
|
* `kopia snap list --all`
|
|
|
|
|
2024-04-21 18:18:29 +00:00
|
|
|
The script is set to save logs in to `C:\Kopia\Kopia_Logs\`.
|
2023-09-04 10:29:42 +00:00
|
|
|
|
|
|
|
### VSS snapshots
|
|
|
|
|
2023-09-05 10:39:36 +00:00
|
|
|
Volume Shadow Copy Service freezes the state of the disk in time and makes
|
2023-09-05 19:08:04 +00:00
|
|
|
this snapshot available to use.
|
|
|
|
This is what allows backup of open files that are in use.<br>
|
2023-09-05 10:39:36 +00:00
|
|
|
[Here's some youtube video on VSS.](https://youtu.be/RUwocwP2ilI?t=85)
|
2023-09-04 10:29:42 +00:00
|
|
|
|
2023-09-05 10:39:36 +00:00
|
|
|
To make use of this feature edit `kopia_backup_scipt.ps1` changing
|
|
|
|
`$USE_SHADOW_COPY = $false` to `$USE_SHADOW_COPY = $true`
|
2023-09-04 10:29:42 +00:00
|
|
|
|
2024-04-21 18:18:29 +00:00
|
|
|
To check if it's set: `kopia policy show --global`,
|
|
|
|
should see there: *OS-level snapshot support: Volume Shadow Copy: when-available*
|
2023-09-05 10:39:36 +00:00
|
|
|
|
2024-04-21 18:18:29 +00:00
|
|
|
Can also check log files, any named snapshot-creat in cli folder, and see
|
|
|
|
entries about *volume shadow copy*. Or also one might execute command
|
|
|
|
`vssadmin list shadows` to see current VSS snapshots and then execute
|
|
|
|
it again during the backup.
|
2023-09-04 10:29:42 +00:00
|
|
|
|
|
|
|
### Kopia install using scoop, machine-wide
|
|
|
|
|
|
|
|
Just something to have note of, if decided to switch to heavy scoop use.
|
|
|
|
|
|
|
|
* open terminal as admin
|
|
|
|
* `Set-ExecutionPolicy Bypass`
|
|
|
|
* `iex "& {$(irm get.scoop.sh)} -RunAsAdmin"`
|
|
|
|
* `scoop install sudo --global`
|
|
|
|
* `sudo scoop install kopia --global`
|
|
|
|
|
|
|
|
---
|
|
|
|
---
|
2023-08-31 18:16:44 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
# Kopia in Docker
|
2023-03-05 09:50:50 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
![kopia_docker_logs](https://i.imgur.com/w57KHvp.png)
|
2023-03-05 09:50:50 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
### Files and directory structure
|
2023-08-31 18:16:44 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
```
|
|
|
|
/mnt/
|
|
|
|
└── mirror/
|
|
|
|
|
|
|
|
/home/
|
|
|
|
└── ~/
|
|
|
|
└── docker/
|
|
|
|
└── kopia/
|
|
|
|
├── kopia_config/
|
|
|
|
├── kopia_cache/
|
|
|
|
├── kopia_logs/
|
|
|
|
├── some_data/
|
|
|
|
├── kopia_repository/
|
|
|
|
├── kopia_tmp/
|
|
|
|
├── .env
|
|
|
|
└── docker-compose.yml
|
|
|
|
```
|
|
|
|
|
|
|
|
* `/mnt/mirror/...` - a mounted network storage share
|
|
|
|
* `kopia_config/` - repository.config and ui-preferences.json
|
|
|
|
* `kopia_cache/` - cache
|
|
|
|
* `kopia_logs/` - logs
|
|
|
|
* `some_data/` - some data to be backed up
|
|
|
|
* `kopia_repository/` - repository location
|
|
|
|
* `kopia_tmp/` - temp used for snapshots
|
|
|
|
* `.env` - a file containing environment variables for docker compose
|
|
|
|
* `docker-compose.yml` - a docker compose file, telling docker how to run the containers
|
|
|
|
|
|
|
|
### docker-compose
|
|
|
|
|
|
|
|
The data to be backed up are mounted in read only mode.<br>
|
2023-09-05 18:02:52 +00:00
|
|
|
To be able to mount snapshots, extra privileges are required and fuse access.
|
2023-09-04 10:29:42 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
services:
|
|
|
|
|
|
|
|
kopia:
|
|
|
|
image: kopia/kopia:latest
|
|
|
|
container_name: kopia
|
|
|
|
hostname: kopia
|
|
|
|
restart: unless-stopped
|
|
|
|
env_file: .env
|
|
|
|
privileged: true
|
|
|
|
cap_add:
|
|
|
|
- SYS_ADMIN
|
|
|
|
security_opt:
|
|
|
|
- apparmor:unconfined
|
|
|
|
devices:
|
|
|
|
- /dev/fuse:/dev/fuse:rwm
|
|
|
|
ports:
|
|
|
|
- "51515:51515"
|
|
|
|
command:
|
|
|
|
- server
|
|
|
|
- start
|
|
|
|
- --tls-generate-cert
|
|
|
|
- --disable-csrf-token-checks
|
|
|
|
- --address=0.0.0.0:51515
|
|
|
|
- --server-username=$USERNAME
|
|
|
|
- --server-password=$KOPIA_PASSWORD
|
|
|
|
volumes:
|
|
|
|
# Mount local folders needed by kopia
|
|
|
|
- ./kopia_config:/app/config
|
|
|
|
- ./kopia_cache:/app/cache
|
|
|
|
- ./kopia_logs:/app/logs
|
|
|
|
# Mount local folders to snapshot
|
|
|
|
- ./some_data:/data:ro
|
|
|
|
# Mount repository location
|
2023-09-04 11:03:32 +00:00
|
|
|
- /mnt/mirror/kopia_repository:/repository
|
2023-09-04 10:29:42 +00:00
|
|
|
# Mount path for browsing mounted snaphots
|
|
|
|
- ./kopia_tmp:/tmp:shared
|
|
|
|
|
|
|
|
networks:
|
|
|
|
default:
|
|
|
|
name: $DOCKER_MY_NETWORK
|
|
|
|
external: true
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
`.env`
|
|
|
|
```bash
|
|
|
|
DOCKER_MY_NETWORK=caddy_net
|
|
|
|
TZ=Europe/Bratislava
|
|
|
|
|
|
|
|
# KOPIA
|
|
|
|
USERNAME=admin
|
|
|
|
KOPIA_PASSWORD=aaa
|
|
|
|
```
|
|
|
|
|
|
|
|
**All containers must be on the same network**.</br>
|
|
|
|
Which is named in the `.env` file.</br>
|
|
|
|
If one does not exist yet: `docker network create caddy_net`
|
|
|
|
|
|
|
|
### Reverse proxy
|
2023-08-31 18:16:44 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
Caddy is used, details
|
|
|
|
[here](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/caddy_v2).</br>
|
|
|
|
|
|
|
|
To function as a repository server, Kopia must be setup with https,
|
|
|
|
which is achieved by using `--tls-generate-cert` flag and removal
|
|
|
|
of `--insecure` flag.
|
|
|
|
|
|
|
|
So now Kopia sits behind Caddy, but caddy needs to be told the traffic is
|
|
|
|
https and to ignore that the certificate is not valid.
|
|
|
|
|
|
|
|
`Caddyfile`
|
|
|
|
```
|
|
|
|
kopia.{$MY_DOMAIN} {
|
|
|
|
reverse_proxy kopia:51515 {
|
|
|
|
transport http {
|
|
|
|
tls
|
|
|
|
tls_insecure_skip_verify
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2023-08-31 18:16:44 +00:00
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
### First run
|
|
|
|
|
|
|
|
![kopia_repo_setup_first_run](https://i.imgur.com/mnn66Hj.png)
|
|
|
|
|
|
|
|
* visit kopia.example.com
|
|
|
|
* create new repository as `Local Directory or NAS`, set path to `/repository`,
|
|
|
|
set password
|
|
|
|
|
|
|
|
Now this container can do backups of mounted stuff in to other mounted places
|
2023-09-04 11:03:32 +00:00
|
|
|
or cloud, while managed through webgui.
|
|
|
|
|
2023-09-04 10:29:42 +00:00
|
|
|
To also make it function as a repository server a user account needs to be added.
|
|
|
|
The users are stored in the repo.
|
|
|
|
|
|
|
|
* exec in to the container<br>
|
|
|
|
`docker container exec -it kopia /bin/bash`
|
|
|
|
* add user@machine and set the password<br>
|
|
|
|
`kopia server user add user1@machine1`
|
2023-09-04 11:03:32 +00:00
|
|
|
* on another machine test with koppiaUI, on the first run:<br>
|
2023-09-04 10:29:42 +00:00
|
|
|
* Pick `Kopia Repository Server`
|
|
|
|
* Server address: `https://kopia.example.com:443`
|
|
|
|
* *Trusted server certificate fingerprint (SHA256)*<br>
|
|
|
|
can be left empty, or if you put something there, it gives you error
|
|
|
|
where it tells you fingerprints of the server to pick from.
|
|
|
|
* In advanced option one can override user@machine with the one set
|
|
|
|
when exec-ed in to the docker container.
|
|
|
|
Or exec again there and add another one.
|
|
|
|
|
|
|
|
### Troubleshooting
|
|
|
|
|
2023-09-04 11:03:32 +00:00
|
|
|
* check kopia docker container logs, I like using [ctop](https://github.com/bcicen/ctop)
|
2023-09-12 19:09:07 +00:00
|
|
|
to see container runtime logs, or the ones mounted in logs directory
|
|
|
|
* DNS issue, check `nslookup kopia.example.com` if on the machine
|
|
|
|
is getting correct iP
|
2023-09-04 10:29:42 +00:00
|
|
|
* Make sure you use port 443 in server address.
|
2023-09-12 20:58:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Kopia backup to Cloud
|
|
|
|
|
2023-09-12 21:21:35 +00:00
|
|
|
## Backblaze B2
|
2023-09-12 20:58:12 +00:00
|
|
|
|
|
|
|
![backblaze_repo_pic](https://i.imgur.com/Yhi2BpM.png)
|
|
|
|
|
2023-09-15 13:47:29 +00:00
|
|
|
[Cheapest](https://www.backblaze.com/cloud-storage/pricing)
|
|
|
|
cloud storage I believe.<br>
|
|
|
|
It cost $6 annualy to store 100GB. Any download is charged extra,
|
|
|
|
that 100GB would cost $1.
|
2023-09-12 20:58:12 +00:00
|
|
|
|
|
|
|
[Official Kopia documentation](https://kopia.io/docs/repositories/#backblaze-b2)
|
|
|
|
|
2023-09-15 13:47:29 +00:00
|
|
|
* [Register](https://www.backblaze.com/sign-up/s3).
|
2023-09-12 20:58:12 +00:00
|
|
|
* Create a new bucket for kopia repository.
|
2023-09-15 13:47:29 +00:00
|
|
|
* note **the bucket name**
|
2023-09-12 20:58:12 +00:00
|
|
|
* Add a new application key with the access enabled to the new bucket.<br>
|
|
|
|
After filling the info the site one time shows `applicationKey`
|
2023-09-15 13:47:29 +00:00
|
|
|
* note **the keyID**
|
|
|
|
* note **the applicationKey**
|
2023-09-12 20:58:12 +00:00
|
|
|
* in Kopia add new repository `Backblaze b2` fill in the required information:
|
|
|
|
Bucket Name, KeyID and the Key.
|
|
|
|
* Set global policy.
|
|
|
|
* Recommend setting compression, `zstd-fastest`.
|
|
|
|
* Set schedule.
|
|
|
|
* Retention rules.
|
|
|
|
* Pick what to backup.
|
|
|
|
* Done.
|
|
|
|
|
2023-09-15 13:47:29 +00:00
|
|
|
In few minutes one can have reliable encrypted cloud backup,
|
|
|
|
that deduplicates and compresses the data.<br>
|
2023-09-12 20:58:12 +00:00
|
|
|
|
2023-09-16 09:32:36 +00:00
|
|
|
**Save the repo password, plus all the info used!**
|
2023-09-12 20:58:12 +00:00
|
|
|
|
2023-09-15 13:47:29 +00:00
|
|
|
Might be worth to check bucket settings, [Lifecycle](https://www.backblaze.com/docs/cloud-storage-lifecycle-rules).
|
|
|
|
I think it should be set to `Keep only the last version of the file`
|
2023-09-12 20:58:12 +00:00
|
|
|
|
|
|
|
To restore files go in to Snapshots > Time > Start time > Mount as Local Filesystem.<br>
|
|
|
|
The snapshot will be mounted as `Y:`
|
|
|
|
|
2023-09-15 13:47:29 +00:00
|
|
|
### cli
|
|
|
|
|
|
|
|
For cli just follow [the official documentation.](https://kopia.io/docs/repositories/#backblaze-b2)
|
|
|
|
The example of commands:<br>
|
|
|
|
|
|
|
|
* `kopia repository create b2 --bucket=rakanishu --key-id=001496285081a7e0000000003 --key=K0016L8FAMRp/F+6ckbXIYpP0UgTky0 --password aaa`
|
2024-04-21 18:18:29 +00:00
|
|
|
* `kopia repository connect b2 --bucket=rakanishu --key-id=001496285081a7e0000000003 --key=K0016L8FAMRp/F+6ckbXIYpP0UgTky0 --password aaa`
|
2023-09-15 13:47:29 +00:00
|
|
|
|
2023-09-15 14:03:20 +00:00
|
|
|
The backup script contains example commands, just commented out.
|
2023-09-15 13:47:29 +00:00
|
|
|
|
|
|
|
|
2023-09-12 20:58:12 +00:00
|
|
|
---
|
|
|
|
---
|