Project Goal
Automate the backup of a publicly reachable Nextcloud instance by using n8n as the central orchestrator. The goal is to ensure regular, encrypted, and verifiable backups of both data and database, stored locally on a Raspberry Pi, while minimizing downtime through controlled maintenance windows.
Initial Situation
- Source: Nextcloud server (publicly reachable, dedicated user
ncbackup).
- Target: Raspberry Pi 4 running n8n in Docker.
- Network: SSH with key-based authentication, no password login.
- Data: Nextcloud data directory + MariaDB database.
Implementation Steps
-
Trigger & Scheduling
- n8n Schedule Trigger runs monthly at 02:00.
- Error Trigger + Wait node to retry if something fails.
-
Controlled Maintenance
- Nextcloud is switched into
maintenance:mode --on before backup.
- Deactivated automatically after success or error.
-
Database Backup
mysqldump of Nextcloud DB (nextcloud_db) stored in /home/ncbackup/tmp/db.sql.
-
Data Backup
rsync copies /var/www/nextcloud/ into staging folder /home/ncbackup/tmp/nextcloud.
- Data + database are compressed into
nextcloud.tar.gz.
-
Transfer & Rotation
- Archive is pulled onto the Raspberry Pi (
backup-user via SSH).
- Data loop downloads items from
/home/data/ individually, skipping volatile dirs (appdata_, updater-).
-
Cleanup
- Temporary folders (
tmp/) and archives are removed both on source and target.
-
Notifications
- On successful backup, Telegram bot notifies the admin: “Nextcloud backup finished”.
Result
- Automated, reliable Nextcloud backups (data + DB).
- Reduced downtime due to controlled maintenance.
- Clean rotation with staging/cleanup.
- Real-time notification via Telegram.
Lessons Learned
- Splitting database + data backups ensures consistency.
- Maintenance mode is essential to avoid file/DB inconsistencies.
- Automating cleanup prevents disk bloat.
- Skipping ephemeral folders (
appdata_, updater-) saves time and storage.
Next Steps (Open Points)
- Backup verification: Regularly test restore procedures to ensure data integrity.
- Incremental backups: Evaluate using tools like
rsync --link-dest, restic, or borg to reduce storage usage and improve efficiency.