270 lines
6.2 KiB
Markdown
270 lines
6.2 KiB
Markdown
<a href="https://git.entropic.pro/Aiden/self-hosting-workshop">Self-hosting Workshop</a> © 2026 by Aiden Gerbrandt is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a><img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg" height="20px"><img src="https://mirrors.creativecommons.org/presskit/icons/by.svg" height="20px"><img src="https://mirrors.creativecommons.org/presskit/icons/nc.svg" height="20px"><img src="https://mirrors.creativecommons.org/presskit/icons/sa.svg" height="20px">
|
|
|
|
# Self-hosting Workshop
|
|
|
|
`<user>` = the username of the admin user account you created during install.
|
|
|
|
## Create Containers
|
|
|
|
```
|
|
sudo loginctl enable-linger <user>
|
|
```
|
|
|
|
Create Folders:
|
|
- `/opt/cloud/nextcloud`
|
|
- `/opt/cloud/database`
|
|
|
|
`sudo chown -R <user>:<user> /opt/cloud`
|
|
|
|
Allow 8080 through the firewall
|
|
|
|
### Pod
|
|
|
|
| Field | Input | Note |
|
|
| ----- | ----- | ----- |
|
|
| Name | cloud | |
|
|
| Owner | `<user>` | |
|
|
| Port Mapping | 8080:80 TCP | Format is `host port:container port` |
|
|
|
|
### Database container
|
|
|
|
Field | Input | Note |
|
|
| ----- | ----- | ----- |
|
|
| Name | postgresql | |
|
|
| Image | docker.io/library/postgres:18 | |
|
|
| Restart Policy | always | Only shows for non-root if linger is enabled
|
|
| Volume | /opt/cloud/database -> /var/lib/postgresql | Writable and Private |
|
|
| Environment Variables | POSTGRES_USER=nextcloud <br> POSTGRES_PASSWORD=mysecretpassword | |
|
|
|
|
### Nextcloud Container
|
|
|
|
| Field | Input | Note |
|
|
| ----- | ----- | ----- |
|
|
| Name | nextcloud | |
|
|
| Image | docker.io/library/nextcloud:latest | |
|
|
| Restart Policy | always | Only shows for non-root if linger is enabled
|
|
| Volume | /opt/cloud/nextcloud -> /var/www/html | Writable and Private |
|
|
|
|
## Migrate Containers to Quadlets
|
|
|
|
### Stop and Remove Containers
|
|
|
|
### Create Volumes
|
|
|
|
`podman volume create postgresql-data`
|
|
|
|
`podman volume create nextcloud-data`
|
|
|
|
### Move data to volumes
|
|
|
|
```sh
|
|
# Postgres data
|
|
podman unshare rsync -a /opt/cloud/database/* ~/.local/share/containers/storage/volumes/postgresql-data/_data/
|
|
|
|
# Nextcloud data
|
|
podman unshare rsync -a /opt/cloud/nextcloud/* ~/.local/share/containers/storage/volumes/nextcloud-data/_data/
|
|
```
|
|
### Create container configs
|
|
|
|
`mkdir -p ~/.config/containers/systemd/`
|
|
|
|
`nano ~/.config/containers/systemd/cloud.pod`
|
|
|
|
```ini
|
|
[Unit]
|
|
Description=Nextcloud Stack
|
|
|
|
[Pod]
|
|
PodName=cloud
|
|
PublishPort=8080:80
|
|
|
|
[Install]
|
|
WantedBy=default.target
|
|
```
|
|
|
|
`nano ~/.config/containers/systemd/postgresql.container`
|
|
|
|
Note: the database password can be stored more securly with an environement file, instead of just putting it in the config!
|
|
|
|
```ini
|
|
[Unit]
|
|
Description=Postgres Database for Nextcloud
|
|
After=network-online.target
|
|
|
|
[Container]
|
|
ContainerName=postgresql
|
|
Pod=cloud.pod
|
|
Image=docker.io/library/postgres:18
|
|
Volume=postgresql-data:/var/lib/postgresql
|
|
Environment=POSTGRES_USER=nextcloud
|
|
Environment=POSTGRES_PASSWORD=mysecretpassword
|
|
|
|
Label=io.containers.autoupdate=registry
|
|
|
|
[Service]
|
|
Restart=always
|
|
```
|
|
|
|
`nano ~/.config/containers/systemd/nextcloud.container`
|
|
|
|
```ini
|
|
[Unit]
|
|
Description=Nextcloud
|
|
After=postgresql.service
|
|
Requires=postgresql.service
|
|
|
|
[Container]
|
|
ContainerName=nextcloud
|
|
Pod=cloud.pod
|
|
Image=docker.io/library/nextcloud:latest
|
|
Volume=nextcloud-data:/var/www/html
|
|
|
|
Label=io.containers.autoupdate=registry
|
|
|
|
[Service]
|
|
Restart=always
|
|
```
|
|
|
|
### Start containers
|
|
|
|
`systemctl --user daemon-reload`
|
|
|
|
`systemctl --user start cloud-pod.service `
|
|
|
|
## Backups
|
|
|
|
### Install Borg Backup
|
|
|
|
Enable EPEL
|
|
|
|
`sudo dnf install epel-release`
|
|
|
|
Install Borg
|
|
|
|
`sudo dnf install borgbackup`
|
|
|
|
### Setup backup storage
|
|
|
|
Make the directory (normally this would be on a dedicated harddrive mounted at `/mnt/backup-drive`)
|
|
|
|
`sudo mkdir -p /mnt/backup-drive/backups`
|
|
|
|
Give yourself ownership of the backups folder
|
|
|
|
`sudo chown <user>:<user> /mnt/backup-drive/backups`
|
|
|
|
Initialize the backup respoitory
|
|
|
|
`borg init --encryption=repokey /mnt/backup-drive/backups`
|
|
|
|
### Perform backup
|
|
|
|
```sh
|
|
# Stop containers
|
|
systemctl --user stop cloud-pod.service
|
|
|
|
# Backup Postgresql podman volume
|
|
podman volume export postgresql-data | borg import-tar --stats /mnt/backup-drive/backups::postgresql_$(date +%Y-%m-%d_%H-%M) -
|
|
|
|
# Backup Nextcloud podman volume
|
|
podman volume export nextcloud-data | borg import-tar --stats /mnt/backup-drive/backups::nextcloud_$(date +%Y-%m-%d_%H-%M) -
|
|
|
|
# Start Containers
|
|
systemctl --user start cloud-pod.service
|
|
```
|
|
|
|
### Restore Backup
|
|
|
|
Stop Containers
|
|
|
|
`systemctl --user stop cloud-pod.service`
|
|
|
|
List backups
|
|
|
|
`borg list /mnt/backup-drive/backups/`
|
|
|
|
Import backups back to podman volumes
|
|
**(replace the backup name based on the date-time)**
|
|
|
|
```sh
|
|
borg export-tar /mnt/backup-drive/backups::postgresql_2026-11-09_21-51 - | podman volume import postgresql-data -
|
|
|
|
borg export-tar /mnt/backup-drive/backups::nextcloud_2026-11-09_22-09 - | podman volume import nextcloud-data -
|
|
```
|
|
|
|
Start Containers
|
|
|
|
`systemctl --user start cloud-pod.service`
|
|
|
|
### Automate Backups
|
|
|
|
#### Create Script
|
|
|
|
`nano ~/backup-nextcloud.sh`
|
|
|
|
```sh
|
|
#!/bin/sh
|
|
|
|
# Stop containers
|
|
systemctl --user stop cloud-pod.service
|
|
|
|
# Backup Postgresql podman volume
|
|
podman volume export postgresql-data | borg import-tar --stats /mnt/backup-drive/backups::postgresql_$(date +%Y-%m-%d_%H-%M) -
|
|
|
|
# Backup Nextcloud podman volume
|
|
podman volume export nextcloud-data | borg import-tar --stats /mnt/backup-drive/backups::nextcloud_$(date +%Y-%m-%d_%H-%M) -
|
|
|
|
# Start Containers
|
|
systemctl --user start cloud-pod.service
|
|
```
|
|
|
|
Make the script executable
|
|
|
|
`chmod +x ~/backup-nextcloud.sh`
|
|
|
|
#### Systemd timer
|
|
|
|
Create Service to run the script
|
|
|
|
Replace with your backup password.
|
|
|
|
Note: this can be done more securly with an environement file, instead of just putting it in the config!
|
|
|
|
`nano ~/.config/systemd/user/backup-nextcloud.service`
|
|
|
|
```ini
|
|
[Unit]
|
|
Description=Run backup script for nextcloud
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
ExecStart="/home/<user>/backup-nextcloud.sh"
|
|
Environment=BORG_PASSPHRASE=<backup password>
|
|
|
|
[Install]
|
|
WantedBy=default.target
|
|
```
|
|
|
|
Create Timer to run the service periodically
|
|
|
|
`nano ~/.config/systemd/user/backup-nextcloud.timer`
|
|
|
|
```ini
|
|
[Unit]
|
|
Description=Run nextcloud backup daily
|
|
|
|
[Timer]
|
|
OnCalendar=*-*-* 4:00:00
|
|
Persistent=true
|
|
|
|
[Install]
|
|
WantedBy=timers.target
|
|
```
|
|
|
|
Reload systemd and enable timer
|
|
|
|
```sh
|
|
systemctl --user daemon-reload
|
|
systemctl --user enable --now backup-nextcloud.timer
|
|
```
|