Scripts for backup/restore

I’ve just updated the scripts.

One new feature was added:
The scripts for backup/restore can now be initialized by a “setup script”. By running setup.sh, some information are gathered (user input) and all the other variables are obtained using OCC.

This way it should be much easier to install these scripts so that they fit to your Nextcloud installation.

However, you should never rely on the setup script. Always check the backup/restore scripts (line by line) before running these for the first time.

You can find the updated scripts here:

Feedback is much appreciated.

1 Like

Amazing script! I only have one problem: I cant locate the web server name! Sorry if its a silly question but i m new to all of these. I have to add i ve installed nextcloud 19 through snap.

apache2 or nginx? Which operation system?

i ve installed nextcloud 19 through snap.

I think the script is not for snap.

linux mint 19.3 xfce. I really don’t know which one, both “cant be found” through systemctl.
It does work with my snap installation since ive edited the script to point to the right directories.

thts the output when i run it:

Backup directory: /dev/Backups 2/NEXTCLOUD_BACKUP
Set maintenance mode for Nextcloud

sudo: php: command not found
Done

Stopping web server

Failed to stop nginx.service: Unit nginx.service not loaded.
Done

Creating backup of Nextcloud file directory

Done

Creating backup of Nextcloud data directory

Ignoring updater backup directory

So i guess it also doesnt put the server in maintanance mode


You find normally the apache2-servername in the virtual hosts configurations.

/etc/apache2/sites-available/
/etc/apache2/sites-enabled (links to other dir)

Sorry. I do not use Snap and do not like it.
I thought Mint does not use it anymore.
Sorry german: https://www.heise.de/news/Linux-Mint-20-Desktop-ohne-Snap-Pakete-4797111.html
Please read for further help:

SNAP Installation change php, apache and nextcloud configs

Yes, the scripts are for a “standalone” installation of Nextcloud only. With Snap you have a ready to use package which is “all in one”. I don’t have any experience with Snap, but I guess that you have to back up the whole Snap package.
I think you cannot use these scripts for this task.

@giorgis1987

Linux Mint:
If linux mint, please do not use snap
https://www.omgubuntu.co.uk/2020/06/enable-snap-apps-linux-mint-20
Please use Ubunut LTS or Debian (server) versions an not the desktop releases of mint.
Mint is not a good idea for a server service like nextcloud.

If you want to install nextcloud on your desktop:
Install Ubunutu LTS or Debian Buster on your desktop and not mint.

I am using lm 19.3

Ok sorry. Linux MInt 19 is also a LTS release and in 2023 you must use Snap without official snap support on Linux Mint. This is a lot of time.

But Mint 19 based on the old Ubuntu 18.04 LTS. I think with the next nextcloud version (20) perhaps at the end of 2020 you must add from a PPA software e.g. newer php- or other software or migratie to Linux Mint 20 (without Snap), to Ubuntu 20.04 LTS (with snap) or Debian Buster (10) (without snap).

Example php versions:

https://packages.ubuntu.com/bionic/php: 7.2 (Ubuntu 18.04 LTS, Mint 19)
https://packages.ubuntu.com/focal/php: 7.4 (Ubuntu 20.04 LTS)

Dear @DecaTec, thank you so much for your helpful backup scripts! :heart_eyes:

Do you mind if I ask you a question? I’m getting an error that I don’t fully understand when executing NextcloudBackup.sh :-/

I managed to get my own NC instance up and running for family and friends around a year ago and now I finally got around to setting up and offsite backup using a Raspberry Pi with external HDD which is peered over wireguard with the NC server.

So naturally, I ran your setup.sh and pointed the destination to pi@[wireguard-IP]:[port]/media/pi/Element/Backup/Nextcloud.

I ran

ping [wireguard-IP]

beforehand to see if it still worked. It did. So I opened a screen and executed NextcloudBackup.sh. This is my output:

Backup directory: pi@[wireguard-IP]:[port]/media/pi/Element/Backup/Nextcloud
Set maintenance mode for Nextcloud...
Maintenance mode enabled
Done

Stopping web server...
Done

Creating backup of Nextcloud file directory...
pi@[wireguard-IP]'s password: ***************
bash: /usr/lib/tar/rmt: No such file or directory
tar: pi@[wireguard-IP]\:[port]/media/pi/Element/Backup/Nextcloud/20201231_131320/nextcloud-filedir.tar: Cannot open: Input/output error
tar: Error is not recoverable: exiting now
Done

Creating backup of Nextcloud data directory...
pi@[wireguard-IP]'s password:

and then that repeats until I cancel the script.

Do you know what could cause this behavior? I’m inclined to believe that the script can’t write to my remote storage as indicated by the Cannot open: Input/output error bit shown above, but rsyncing multiple directories of several GB each into remote directories that rsync had to create first was no problem. :thinking:

Also, two other things I noticed:

  • right now, NextcloudBackup.sh creates backups before checking if the destination is writeable, yes? It might be an idea to have the script check whether the destination (be it a local external HDD, a local folder or a remote storage) is ready first before creating backups.
  • I had to fiddle a bit with trailing slashes in the destination folders because I kept seeing things like [remote_dir]/Nextcloud//20201231_131320, which, I assume, is likely to cause errors?

Hope you’re staying healthy in these times! :wink:

I think that this line is the cause of the problem. But honestly, I cannot tell you why it’s trying to use this lib, maybe this has something to do with wireguard?

The double slashes may occur when you call the script with a backup destination folder with a trailing slash. But this shouldn’t be a problem at all.

Huh. Yeah, I was wondering why it would need to look into /usr/lib/tar/rmt. I dabbled a little further and it seems now that this particular problem only appears when I append the port number to backupMainDir. So

pi@[wireguard-IP]:[port]/media/pi/Element/Backup/Nextcloud/

leads to

Creating backup of Nextcloud file directory...
pi@[wireguard-IP]'s password:
bash: /usr/lib/tar/rmt: No such file or directory
tar: pi@[wireguard-IP]\:[port]/media/pi/Element/Backup/Nextcloud//20201231_145502//nextcloud-filedir.tar: Cannot open: Input/output error
tar: Error is not recoverable: exiting now
Done

I think this is the correct syntax when giving the script a remote storage, however, since omitting the port invariably produces locally stored backups. The script opens a new dir in the dir I started the process in and then tars everything there. It also does not ask me for an ssh password, so my comment about making sure the destination directory is moot, obviously :smiley:

So, in essence, I guess I can’t really use the script given my backup storage solution?

Another suggestion: Can you mount the remote dir before starting the backup script? Then it should behave like a local dir actually.

Great script!
Very much thanks for publishing it!!!

For those interested, below are two Nextcloud backup and restore scripts installed through snap packages.

  • Script Usando Rsync
  • Script Usando Borg e rclone

Hi, i installed Nextcloud on Debian 11 and apache2. When i start the script, they make a backup of data and nextcloud files, but not the database, and the nextcloud stay in maintenance and apache2 would not be automatically restarted. I checked the configs, and i manually changed mysql to mariadb, but same result. So i can’t find what is wrong. Any idea how i can check it?

There should be an error message when the script is run.
When only the DB is missing from the backup, you could manually execute the single steps from the script in order to get the exact line where an error is thrown.

The last message ist this:
17:54:42: Creating backup of Nextcloud data directory

Ignoring Nextcloud updater backup directory
tar: ./back/20220930_175006/nextcloud-datadir.tar.gz: file changed as we read it
root@cloud-02:/skript/Nextcloud-Backup-Restore#

Thanks for your reply.

Ouh
Now i understand it

The backup directory must not be mounted in the data directory of the nextcloud
 i mounted in /data/back and the /data is the data directory of nextcloud. Nice to know :smiley: