Backup Nextcloud

Moin,

I’m using UCS 4.4.6 with Nextcloud 20.0.2-0.
In the last days I read a lot about backup and restore. But it’s difficult for me to get a specific hint for backup a nextcloud-installation on a ucs.

I found

But what does it mean?

To backup a nextcloud-installation I only have to do two things:

  1. Save the directory /var/lib/univention-appcenter/apps/nextcloud/data
  2. To backup the database with the pg_dump utility.

To restore a nextcloud-installation I only have to do two things:

  1. To overwrite the directory in the new installation with the save directory
  2. To restore the database with the pg_restore utility.

I use bareos for this and have two scripts in /usr/local/sbin/.

nextcloud_before_backup.sh:

#!/bin/bash
 dumpdir=/var/backups/backup-sql
 nc_dumpfile=$dumpdir/nc-postgresdump.sql
 if [ ! -d  "$dumpdir" ]
 then
     mkdir -p "$dumpdir"
 fi
 /usr/local/sbin/occ maintenance:mode --on
PGPASSWORD="mysecret" pg_dump nextcloud -h localhost -U nextcloud -f $nc_dumpfile

and nextcloud_after_backup.sh:

#!/bin/bash
/usr/local/sbin/occ maintenance:mode --off

I’ve created a script/alias for the occ-command with the ucs docker-app like:

#!/bin/bash
univention-app shell nextcloud sudo -u www-data /var/www/html/occ "$@"

If you don’t want to do that just change the commands for maintenance accordingly.

In bareos I use the scripts with the job:

  ClientRunBeforeJob = "/usr/local/sbin/before_backup.sh"
  ClientRunAfterJob = "/usr/local/sbin/nextcloud_after_backup.sh"

I haven’t done a full circle with the restore yet - so as always - use with care. There is a bareos/nextcloud whitepaper I’ve used for this. The solution requires a maintenance circle - so I guess is suitable for smaller environments.

Edit: so in between the scripts at least two locations to backup:

1) /var/lib/univention-appcenter/apps/nextcloud/data
2) /var/backups/backup-sql

Best,
Bernd

Thanks. It seems the same.

  1. saving the database with pg_dump
  2. saving the directory

My question is: What’s the way to restore without loosing information in nextcloud?

  1. using pg_restore to restore the database
  2. overwriting the directory with the backup
    nothing else?

Yes, as long as the pg_dump reflects the time of the directory backup.
That’s why it is advised (in this solution) to set nextcloud in maintenance mode before the backup.

Ok, I made no mention of the maintenance mode.

My question is focussed on the restore-process.

Can I use the described solution for restoring all data in a new nextcloud-installation?

Mastodon