Scripts for backup/restore

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:

Yes, additional data (like backups) should not be saved in the NC data directory.