You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
5.3 KiB
Markdown

1 year ago
# 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)
1 year ago
Kopia is a very new open source backup utility with basicly **all** modern features.</br>
1 year ago
Cross-platform, deduplication, encryption, compression, multithreaded speed,
1 year ago
fully build in cloud storage support, GUI versions, snapshots mounting,...
1 year ago
1 year ago
Written in golang.
1 year ago
1 year ago
In this setup kopia cli is installed directly on a docker host.</br>
A kopia repository is set up.<br>
A script that backs up data is scheduled to run regularly<br>
Bonus info on mounting remote NAS storage on boot using systemd<br>
1 year ago
1 year ago
# Some aspects of Kopia
1 year ago
* Backup configuration is stored in a repository where backups are stored.<br>
This includes global policy, that is global in sense of a repo, not all of kopia.
* 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/)
1 year ago
and set policy: `--ignore-cache-dirs true`
1 year ago
* Maintence is automatic
* ..
1 year ago
# Files and directory structure
```
/home/
1 year ago
│ └── ~/
│ └── docker/
│ ├── container-setup #2
│ ├── container-setup #1
│ ├── ...
1 year ago
/mnt/
1 year ago
│ └── mirror/
│ └── KOPIA/
│ └── arch_docker_host/
/opt/
└── kopia-backup-home-etc.sh
1 year ago
```
1 year ago
only the script `kopia-backup-home-etc.sh` in /opt is created<br>
1 year ago
uf, systemd unit files too, but I am not "drawing" /etc/systemd/system/ up there...
1 year ago
even this will probably get deleted
1 year ago
# The setup
1 year ago
### install kopia
1 year ago
for arch linux, kopia is on AUR `yay kopia-bin`
1 year ago
### the initial steps
1 year ago
use of sudo so that kopia has access everywhere<br>
1 year ago
* **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**
1 year ago
1 year ago
`sudo kopia snapshot create /home/spravca/docker /etc`<br>
`sudo kopia snapshot list`<br>
1 year ago
1 year ago
* **mounting a backup**
1 year ago
1 year ago
`sudo kopia snapshot list`<br>
1 year ago
`sudo kopia mount k7e2b0a503edd7604ff61c68655cd5ad7 /mnt/tmp &`<br>
`sudo umount /mnt/tmp`<br>
1 year ago
1 year ago
### the backup script
1 year ago
`/opt/kopia-backup-home-etc.sh`
1 year ago
```bash
1 year ago
#!/bin/bash
1 year ago
1 year ago
#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
1 year ago
1 year ago
REPOSITORY_PATH='/mnt/mirror/KOPIA/docker_host_kopia'
BACKUP_THIS='/home /etc'
export KOPIA_PASSWORD='aaa'
1 year ago
1 year ago
kopia repository connect filesystem --path $REPOSITORY_PATH
kopia snapshot create $BACKUP_THIS
kopia repository disconnect
```
1 year ago
1 year ago
### Automatic execution using systemd
1 year ago
1 year ago
Usually cron is used, but systemd provides better logging and control,
1 year ago
so better get used to using it.<br>
[Heres](https://github.com/kopia/kopia/issues/2685#issuecomment-1384524828)
some discussion on units. Will be editing it for ntfy
1 year ago
1 year ago
[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)
1 year ago
```kopia-home-etc.service```
```ini
[Unit]
Description=kopia backup
Wants=network-online.target
After=network-online.target
ConditionACPower=true
1 year ago
OnFailure=ntfy@failure-%p.service
# OnSuccess=ntfy@success-%p.service
1 year ago
[Service]
Type=oneshot
# Lower CPU and I/O priority.
Nice=19
CPUSchedulingPolicy=batch
IOSchedulingPriority=7
IPAccounting=true
PrivateTmp=true
Environment="HOME=/root"
1 year ago
ExecStart=/opt/kopia-backup-home-etc.sh
1 year ago
```
```kopia-home-etc.timer```
```
[Unit]
Description=Run kopia backup
[Timer]
1 year ago
OnCalendar=*-*-* 02:00:00
RandomizedDelaySec=10min
1 year ago
Persistent=true
[Install]
WantedBy=timers.target
```
1 year ago
1 year ago
# Mounting backup storage using systemd
1 year ago
1 year ago
* file are placed in `/etc/systemd/system`
1 year ago
* the name of mount and automount files MUST correspond with the path<br>
instead of `/` a `-` is used, but otherwise it must be the mounting path in name
1 year ago
* for mounting that does not fail on boot if network there are network issues,
and mounts the target only on request - enable `automount` file,
not `mount` file, so:<br>
1 year ago
`sudo systemctl enable mnt-mirror.automount`
1 year ago
1 year ago
`mnt-mirror.mount`
```ini
[Unit]
Description=3TB truenas mirror mount
1 year ago
1 year ago
[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
1 year ago
1 year ago
[Install]
WantedBy=multi-user.target
```
`mnt-mirror.automount`
```ini
[Unit]
Description=3TB truenas mirror mount
[Automount]
Where=/mnt/mirror
[Install]
WantedBy=multi-user.target
```
1 year ago
# Remote backup