Scripts for backup/restore

I always do stop the webserver. Because my files are on external storage (which is not part of the backup), backup is done very quickly.
Feel free to test if stopping the webserver is really necessary for your needs. Maintenance mode should be enough for the NC backup.

Hey, using this could I link rsync so that after a backup it then moves the backup to an external storage server for an external backup?

Thanks, Tom.

Hi Tom,

you could also edit the script in order that backups are saved directly to an external storage server.

Thanks for the scrip. Have added into cron and works fine very night around 03:00 AM, so no need to worry for stopping the server.

As a side comment, I came to nextcloud in Ubuntu from NextcloudPi running in a Raspberry 3. The NextcloudPi has an admin module to easily configire/use most of the admin requirements, including ufw, rsync, ssl, …

I’ve introduced a versioning of the scripts now. The version can be found in the header of the scripts. I think, now it’s easier to update already used scripts when some changes were made in the GitHub repo.

Also, v1.0.0 comes with some changes improving the maintainability.

You can also download an archive from the release page:

1 Like

I’ve moved from GitHub to Codeberg.
You can find the repository with the scripts here:

Sir if I change your script and change nginx to apache2 its everything will be ok?

Nice script! Thank you very much.
Just one question (maybe i dont get it right)
why do you need to stop the webserver during the backup?
isnt it enough to put it to maintenance mode?
i mean now my clients wont get the information that the server is in maintenance right now because the webserver is not running?


Hello Matthias,

it should work when the webserver is still running and only the maintenance mode of NC is active.
However, I do stop the webserver in order to make absolutely sure that there are no activities in NC.

When your concern is regarding other web applications running on the same server, you could also disable the virtual host for NC and reload the webserver config. This makes sure that no other web application will become unavailable while the backup of NC is running.

Best regards,

OK, i removed the stop/start of the webserver from the script.

my concern is that the nextcloud-clients (for example my brother who is using my server doesnt get the “maintenance/backup in progress” notice when i stop the webserver. so for the user out there it looks like a problem.

and a suggestion/small improvement

i added the “-I pigz” option to the tar call to enable parallel gzip

tar -I pigz -cpf "${backupdir}/${fileNameBackupFileDir}" -C "${nextcloudFileDir}" .

just want to say thanks.

take your scripts - reworked them to use it with docker installation in the omv forums :wink:
so here is the link :wink:
omv forum - Nextcloud Docker Backup with DB
i also crosslink this post there.

maybe you can need the improvement of getting some needed values from the config.php file :wink:

thx again,

is it possible to backup/restore a specific user incl. his data?

No, this a always a full backup/restore.
The data belonging to one user is scattered in the data dir and the database. That would be a whole lot of (manual) work.

thank you

HI, Thanks for this awesome code.

Would you have some explanation on how to run the script when using openmediavault and docker/portainer to run the nextcloud instance? What does it change to your todo list?



the script has to be run in the same machine as the NC instance. So, my first guess would be to include it somehow in the docker container itself.
But there I don’t have any experience as I’m running my NC instances without Docker.

Best regards,

I think for smaler installation you can use “tar” within the script.
But what about with bigger installation?
Perhaps you can better use “rsync” with “–link-dest” for incremental backups.

Indeed, I’ll pack the output in a borg backup repository. This way, the deduplicating really works great and the backups remain pretty small (depends on how many files have changed between two backup runs).

1 Like

I’m curious about this too, because when running Nextcloud in docker from Rancher if I stop the web server it kills the container. So I have not been stopping the web server when testing updates from 14 --> 15, and 15 --> 16.

I think you could backup and restore a single user without the information from the database, but you would have to php occ file:scan USERNAME after the restore to make sure the files showed up.