Nextcloud
Setup
sudo snap install nextcloud
- Allow 80 and 443 in firewall
- Edit trusted domain
sudo nextcloud.occ config:system:set trusted_domains 1 --value=domain.example.com
sudo nextcloud.enable-https lets-encrypt
- Add NAT translation on the home router
- Add domain A record in my DNS zone
- Setup Sendgrid for SMTP server
Other stuff
- Host
X.X.X.X
was not connected to because it violates local access rules. → Fix here - Change trash bin configuration: see this article
Cloudflare Tunnel
- Goal: don’t expose Public IP, be protected against DDoS, avoid firewall set-up
- Introduction to Cloudflare Tunnel
- Setup
- Setup the Cloudflare Package Repo if needed
- Edit
/etc/hosts
file to add certificate DNS name to being able to self resolve it - and use this DNS name in the Cloudflare Tunnel Public Hostname (notlocalhost
, you may end up with Error 502 as the certificate DNS andlocalhost
won’t match) - Follow the New Tunnel guide in the Cloudflare Tunnel dashboard
- Or if you want to do it manually
- Follow the step-by-step CLI guide
- Move configuration from
~/.cloudflared/
to/etc/cloudflared/
before running the tunnel -
Install
cloudflared
as a service:sudo cloudflared service install sudo systemctl start cloudflared sudo systemctl enable cloudflared
- Quick reference:
cloudflared tunnel list
to list all tunnels
Integrations with other devices
Outlook calendar
Use Outlook CalDav Synchronizer - but untestes
Maintenance
Data
sudo nextcloud.export -abc
to export everything except user datasudo nextcloud.occ files:scan --all
to force scan all files, useful to fix checksum issuessudo nextcloud.occ files:scan-app-data
to force scan all app data- User data are in
/var/snap/nextcloud/common/
Backup
Based on How To Backup Nextcloud
- Create
ncbackup
user -
Edit
/usr/sbin/ncbackup.sh
with#!/bin/bash # Output to a logfile exec &> /home/ncbackup/Backups/Logs/"$(date '+%Y-%m-%d').txt" echo "Starting Nextcloud export..." # Run a Nextcloud backup without data (will be saved later with Duplicati) nextcloud.export -abc echo "Export complete" # Clean the Backup/Data folder rm -r /home/ncbackup/Backups/Data/* # Move backup from yyyymm... directory to our directory. 2* is used to filter out folder starting with 2, like 2020 mv /var/snap/nextcloud/common/backups/2*/* /var/snap/nextcloud/common/backups/2*/.* /home/ncbackup/Backups/Data/ # Remove backup folder rm -r /var/snap/nextcloud/common/backups/2*/ echo "Nextcloud backup successfully moved to /home/ncbackup/Backups/Data/" # Remove logs older than 14 days find /home/ncbackup/Backups/Logs -mtime +14 -type f -delete echo "Removed old logs" echo "Nextcloud backup completed successfully."
- Make the file executable
sudo chmod +x /usr/sbin/ncbackup.sh
- Allow the file to be executed without sudo interaction
sudo visudo
ncbackup ALL=(ALL) NOPASSWD: /usr/sbin/ncbackup.sh
- Remove shell access from
ncbackup
usersudo usermod -s /sbin/nologin ncbackup
- To add it back
sudo usermod -s /bin/bash ncbackup
- To add it back
- Schedule the backup
- Open crontab
sudo crontab -u ncbackup -e
- Make the script run at 0200 every day
0 2 * * * sudo /usr/sbin/ncbackup.sh
- Open crontab
Sources:
- Reference page for the Snap
- How To Setup A Nextcloud Server In Ubuntu
- OCC Command line tool
- Most notably the config command instead of changing
config.php
- Get example:
sudo nextcloud.occ config:system:get version
- Set example:
sudo nextcloud.occ config:system:set logtimezone --value="Europe/Berlin"
- Most notably the config command instead of changing
Good apps
Preview Generator for thumbnails
- Suggested: change the preview generation behavior - great post here, I just changed quality to 70
- Install from app store
sudo nextcloud.occ preview:generate-all
- Make a script for that and schedule it
-
Edit
/usr/sbin/ncpreviewgenerator.sh
with#!/bin/bash # Output to a logfile exec &> /home/ncbackup/PreviewGenerator/"$(date '+%Y-%m-%d %T').txt" echo "Starting Nextcloud Preview Generator (with logs)..." nextcloud.occ preview:pre-generate -vvv echo "Done." # Remove logs older than 14 days find /home/ncbackup/PreviewGenerator -mtime +14 -type f -delete echo "Removed old logs" echo "Nextcloud Preview Generator completed successfully."
sudo chmod +x /usr/sbin/ncpreviewgenerator.sh
sudo visudo
ncbackup ALL=(ALL) NOPASSWD: /usr/sbin/ncpreviewgenerator.sh
- Remove shell access from
ncbackup
usersudo usermod -s /sbin/nologin ncbackup
- Schedule the backup
- Open crontab
sudo crontab -u ncbackup -e
- Make the script run every 30 min
30 * * * * sudo /usr/sbin/ncpreviewgenerator.sh
- Open crontab
-
Notes:
- Use
-vvv
argument to output each opened file
RainLoop Webmail
- Install plugin
- Login to admin panel in
root/index.php/apps/rainloop/app/
- Change admin password
- Add domain
- Login with standard link using user mail and mail password
- Enable automatic login in Settings > Additional Settings
Music
OVH Dynamic IP
OK, it’s not an app, just a script that I run every 6 hours.
You need to setup first a DynHost username - see this documentation and calculate the basic header.
#!/bin/bash
# Output to a logfile
exec &> /home/ncbackup/DDNS/"$(date '+%Y-%m-%d %T').txt"
echo "Starting DDNS update ..."
curl -i -H "Authorization: Basic COPY_YOUR_KEY_HERE=" ""https://www.ovh.com/nic/update?system=dyndns'&'hostname=DOMAIN.EXAMPLE.ORG""
# Remove logs older than 14 days
find /home/ncbackup/DDNS -mtime +14 -type f -delete
echo "Removed old logs"