Skip to main content

Backing Up Nextcloud

Regular backups are essential for any self-hosted service. This guide covers how to back up your Nextcloud instance running in Podman/Docker.

Prerequisites

  • Access to the server via SSH.
  • sudo privileges.

Backup Strategy

We need to backup two things:

  1. The Database (PostgreSQL/MariaDB).
  2. The Data Directory (Your files and config).

1. Database Backup

If you are using PostgreSQL, use pg_dump.

podman exec -t nextcloud-db pg_dumpall -c -U nextcloud > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql

2. File Backup

Use rsync to copy your data directory to a separate location (e.g., an external drive or a remote server).

rsync -Aax /path/to/nextcloud/data /path/to/backup/location

Automating with Cron

You can create a script and run it daily via cron.

0 3 * * * /home/user/scripts/backup-nextcloud.sh