2023-01-21 20:48:29 +00:00
|
|
|
# Kopia
|
|
|
|
|
|
|
|
###### guide-by-example
|
|
|
|
|
|
|
|
![logo](https://i.imgur.com/A2mosM6.png)
|
|
|
|
|
|
|
|
WORK IN PROGRESS<br>
|
|
|
|
WORK IN PROGRESS<br>
|
|
|
|
WORK IN PROGRESS<br>
|
|
|
|
|
|
|
|
# Purpose & Overview
|
|
|
|
|
|
|
|
Backups.
|
|
|
|
|
|
|
|
* [Official site](https://kopia.io/)
|
|
|
|
* [Github](https://github.com/kopia/kopia)
|
|
|
|
|
2023-02-05 18:26:14 +00:00
|
|
|
Kopia is a new open source backup utility with basicly **all** modern features.</br>
|
2023-01-21 20:48:29 +00:00
|
|
|
Cross-platform, deduplication, encryption, compression, multithreaded speed,
|
2023-02-07 17:13:11 +00:00
|
|
|
native cloud storage support, GUI versions, repository replication, snapshots mounting,...
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-01-24 07:52:43 +00:00
|
|
|
Written in golang.
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-02-07 17:13:11 +00:00
|
|
|
In this setup kopia cli is used to backup docker containers and the host,
|
|
|
|
but general use and concepts are universal.</br>
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-01-24 07:52:43 +00:00
|
|
|
# Some aspects of Kopia
|
|
|
|
|
2023-03-05 09:50:50 +00:00
|
|
|
* Kopia configuraiton uses term policies to apply to various
|
|
|
|
- global policy, from which repos inherit settings
|
|
|
|
- repos policy created on repo creation
|
2023-01-29 12:50:28 +00:00
|
|
|
* Backup configuration is stored in a repository where backups are stored.<br>
|
|
|
|
* You connect to a repository before using it, and disconnect afterwards.<br>
|
|
|
|
Only one repository can be connected at the time(at least for cli version).
|
|
|
|
* Currently to ignore a folder - `CACHEDIR.TAG` file can be placed inside,
|
|
|
|
with specific [content](https://bford.info/cachedir/)
|
2023-01-29 12:30:34 +00:00
|
|
|
and set policy: `--ignore-cache-dirs true`
|
2023-01-24 07:52:43 +00:00
|
|
|
* Maintence is automatic
|
|
|
|
* ..
|
2023-01-21 20:48:29 +00:00
|
|
|
|
|
|
|
# Files and directory structure
|
|
|
|
|
|
|
|
```
|
|
|
|
/home/
|
2023-01-24 07:52:43 +00:00
|
|
|
│ └── ~/
|
|
|
|
│ └── docker/
|
|
|
|
│ ├── container-setup #2
|
|
|
|
│ ├── container-setup #1
|
|
|
|
│ ├── ...
|
2023-01-21 20:48:29 +00:00
|
|
|
│
|
|
|
|
/mnt/
|
2023-01-24 07:52:43 +00:00
|
|
|
│ └── mirror/
|
|
|
|
│ └── KOPIA/
|
|
|
|
│ └── arch_docker_host/
|
|
|
|
│
|
|
|
|
/opt/
|
|
|
|
└── kopia-backup-home-etc.sh
|
2023-01-21 20:48:29 +00:00
|
|
|
```
|
|
|
|
|
2023-01-29 12:30:34 +00:00
|
|
|
only the script `kopia-backup-home-etc.sh` in /opt is created<br>
|
2023-01-29 12:50:28 +00:00
|
|
|
uf, systemd unit files too, but I am not "drawing" /etc/systemd/system/ up there...
|
2023-01-29 12:30:34 +00:00
|
|
|
even this will probably get deleted
|
|
|
|
|
2023-01-21 20:48:29 +00:00
|
|
|
# The setup
|
|
|
|
|
2023-01-29 12:30:34 +00:00
|
|
|
### install kopia
|
2023-01-21 20:48:29 +00:00
|
|
|
|
|
|
|
for arch linux, kopia is on AUR `yay kopia-bin`
|
|
|
|
|
2023-01-29 12:30:34 +00:00
|
|
|
### the initial steps
|
|
|
|
|
2023-01-21 20:48:29 +00:00
|
|
|
|
|
|
|
use of sudo so that kopia has access everywhere<br>
|
|
|
|
|
2023-01-29 12:30:34 +00:00
|
|
|
* **the policy info and change**
|
|
|
|
|
|
|
|
`sudo kopia policy get --global`<br>
|
|
|
|
`sudo kopia policy list`<br>
|
|
|
|
`sudo kopia policy set --global --ignore-cache-dirs true --keep-annual 1 --keep-monthly 6 --keep-weekly 4 --keep-daily 14 --keep-hourly 0 --keep-latest 14`<br>
|
|
|
|
|
|
|
|
* **repo creation**
|
|
|
|
|
|
|
|
`mkdir -p /mnt/mirror/KOPIA/docker_host_kopia`<br>
|
|
|
|
`sudo kopia repository create filesystem --path /mnt/mirror/KOPIA/docker_host_kopia`<br>
|
|
|
|
`sudo kopia repository connect filesystem --path /mnt/mirror/KOPIA/docker_host_kopia`<br>
|
|
|
|
`sudo kopia repository status`<br>
|
|
|
|
|
|
|
|
* **manual 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-01-29 12:30:34 +00:00
|
|
|
* **mounting a backup**
|
2023-01-24 07:52:43 +00:00
|
|
|
|
2023-01-29 12:50:28 +00:00
|
|
|
`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-01-29 12:30:34 +00:00
|
|
|
### the backup script
|
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
|
|
|
|
2023-01-29 12:30:34 +00:00
|
|
|
#sudo kopia policy set --global --ignore-cache-dirs true --keep-annual 1 --keep-monthly 6 --keep-weekly 4 --keep-daily 14 --keep-hourly 0 --keep-latest 14
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-01-24 07:52:43 +00:00
|
|
|
REPOSITORY_PATH='/mnt/mirror/KOPIA/docker_host_kopia'
|
|
|
|
BACKUP_THIS='/home /etc'
|
2023-03-05 09:50:50 +00:00
|
|
|
KOPIA_PASSWORD='aaa'
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-03-05 09:50:50 +00:00
|
|
|
kopia repository connect filesystem --path $REPOSITORY_PATH --password $KOPIA_PASSWORD
|
2023-01-24 07:52:43 +00:00
|
|
|
kopia snapshot create $BACKUP_THIS
|
|
|
|
kopia repository disconnect
|
|
|
|
```
|
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-01-29 21:21:19 +00:00
|
|
|
[ntfy](https://github.com/binwiederhier/ntfy) is used for notifications,
|
|
|
|
more info [here](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/gotify-ntfy-signal#linux-systemd-unit-file-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
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
```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-02-05 18:26:14 +00:00
|
|
|
# Mounting network storage using systemd
|
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
|
|
|
|
|
|
|
# Remote backup
|
|
|
|
|
2023-03-05 09:50:50 +00:00
|
|
|
... some day ...
|
2023-01-21 20:48:29 +00:00
|
|
|
|
2023-03-05 09:50:50 +00:00
|
|
|
# Kopia in Windows
|
|
|
|
|
2023-06-18 12:31:32 +00:00
|
|
|
While GUI version seems like a way to go.. its not there yet.
|
|
|
|
The way the schedule is running - it uses is running only under a user, theres no certainty it will run.
|
2023-03-05 09:50:50 +00:00
|
|
|
|
|
|
|
So here goes cli version
|
|
|
|
|
|
|
|
* [download](https://github.com/kopia/kopia/releases/) latest named kopia-X.XX.X-windows-x64.zip
|
|
|
|
, \~11MB
|
|
|
|
* extract, move to `C:\kopia`
|
|
|
|
* download `win_vss_before.ps1` and `win_vss_after.ps1` from this repo,
|
|
|
|
or crete them from
|
|
|
|
[here](https://kopia.io/docs/advanced/actions/#windows-shadow-copy)
|
|
|
|
* kopia-backup-home-etc.sh
|
|
|
|
|
|
|
|
* powershell as as administrator
|
|
|
|
* --enable-actions
|
|
|
|
* in tray, right click on the icon - `Launch At Startup`<br>
|
|
|
|
this creates registry entry - *HKCU\Software\Microsoft\Windows\CurrentVersion\Run\KopiaUI*
|
|
|
|
*
|
|
|
|
|
|
|
|
kopia policy set <target_dir> --before-folder-action "powershell -WindowStyle Hidden <path_to_script>\before.ps1"
|
|
|
|
kopia policy set <target_dir> --after-folder-action "powershell -WindowStyle Hidden <path_to_script>\after.ps1"
|