Restoring backup via nc-restore fails and it's the only one I got

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 28.0.8.1
  • Operating system and version (e.g., Ubuntu 24.04):
    • Armbian-unofficial 25.8.1 Bookworm \l . 6.12.41-current-bcm2711 (aarch64)
  • Web server and version (e.g, Apache 2.4.25):
    • apache2
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • not sure
  • PHP version (e.g, 8.3):
    • 8.3.28
  • Is this the first time you’ve seen this error? (Yes / No):
    • Yes
  • When did this problem seem to first start?
    • When I tried to restore my NCP from backup after I bricked it and had to wipe the SD Card
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • NCP via SD Card plugged into a RaspberryPi 5
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • don't think so.

Summary of the issue you are facing:

I accidently borked my NCP and am trying to restore it from the backup I had created with ncp-backup a year ago. However, the process fails with an error and a giant amount of garbled text in the log. I’m trying the restore with ncp-restore from a fresh clean install on the same RaspberryPi 5 that it was created on. Would be great if someone more knowledgable than me could have a look at this – I only have this one backup. After the failed restore, nextcloud isn’t starting anymore and there seem to be a lot of errors with the database, but I don’t really have a clue what’s going wrong.

Steps to replicate it (hint: details matter!):

  1. Boot RaspberryPi from freshly flashed SD card

  2. Go through initial setup, create admin and user account

  3. Add internal SSD to fstab so it auto-mounts at boot

  4. Reboot the device and confirm the SSD (which contains /ncdata, /ncdatabase and swap) is mounted correctly at /mnt

  5. Activate SSH admin access via web UI

  6. SSH into the device and launch nc-config

  7. Select nc-restore and point it towards the only nc-backup I have, which is on the mounted SSD (/mnt/backups/nextcloud-bkp_20240820_1724156326.tar.gz)

  8. Watch the restore process start and then fail (see logs below)

  9. Cry over the prospect of having to set up the whole box again from scratch

Log entries

Nextcloud

Please provide the log entries from your Nextcloud log that are generated during the time of problem (via the Copy raw option from Administration settings->Logging screen or from your nextcloud.log located in your data directory). Feel free to use a pastebin/gist service if necessary.

Log here: https://pastebin.com/MFepmRVg

And at the end of this 1MB log file:

\CBD@\rq\AC\8B\\DB\0V\C0k\9Aw\9C\A2\\CBD@\\F7\\E4a\A1\\D6\0V\C0=\9BU\9F\\CBD@\8C\B9k	\F9\0V\C0$\97\FF\90~\\CBD@\8C\B9k	\F9\0V\C0'),
('125779_2_i2','125779_2',-1,125779,'\\E6\0\0\0\0\0\0\0\0\0\0\0\99*\95\\D4\\C9D@s\\D7\\F2V\C0\\D2o_a\\CE\\C9D@h\"lxzV\C0D\8Bl\\E7\FB\\C9D@\ZQ\\DAe|V\C0\95\\D4	h\\CAD@}гY\\F5V\C0\99*\95\\D4\\C9D@s\\D7\\F2V\C0')
--------------

ERROR 2013 (HY000) at line 92421: Lost connection to server during query
Error restoring nextcloud database
Cleanup...

The backup is too dated, period.
You may try to setup an instance with -say- v. v1.54.3, get the disk configuration right , try to restore your dated backup.

Try to restore your nextcloud to the same versions where you took the backup from.

Say you backed up nextcloud 20 then install nextcloud 20. Restore backup then upgrade to the latest by upgrading up 1 version at a time.

So when nc20 is running upgrade to 21 check everything is working and all database tables are okay then upgrade to 22 etc, etc…

As far as I can see all the data is restored properly. there is just the sql issue. Though most older .sql backups should be able to restore to newer mariadb versions.

Alternative you can manually restore the backup. and do a files:scan.

Thanks, both! I’ll try to flash an older version and do the restore again.

Considering that I’ve always updated my NCP whenever an update came out, can we derive from the date of the backup which NCP version I should be installing now? The date is Aug 20, 2024. Thank you!

1 Like

This might help you determine which to try: Releases · nextcloud/nextcloudpi · GitHub

As mentioned before.

Thank you! I’ve installed the old version and the restore process did not throw any errors. However, it seems the process is stuck at the following stage – it’s been over an hour and CPU load is low, so I’m not sure whether I should wait or reboot? When reloading the web UI, none of the settings the log claims to have restored are visible, but maybe will be after a reboot.

I don’t want to interrupt this scan, of course, if it’s actually going on. But I don’t see any sign of that. Thoughts?

±--------±-------±----±--------±--------±-------±-------------+
| Folders | Files | New | Updated | Removed | Errors | Elapsed time |
±--------±-------±----±--------±--------±-------±-------------+
| 23956 | 541556 | 0 | 805783 | 1556 | 0 | 00:53:49 |
±--------±-------±----±--------±--------±-------±-------------+
Installing template ‘php/opcache.ini.sh’…
System config value tempdirectory set to string /mnt/ncdata/data/tmp
System config value logfile set to string /mnt/ncdata/data/nextcloud.log
System config value trusted_domains => 11 set to string XXXXXXXXXXXXXXXXXXX
System config value trusted_domains => 1 set to string XXX.XXX.XXX.XXX
System config value trusted_domains => 14 set to string nextcloudpi
System config value trusted_domains => 3 set to string nextcloudpi
System config value overwrite.cli.url set to string https://nextcloudpi/
System config value trusted_proxies => 11 set to string 127.0.0.1
System config value trusted_proxies => 12 set to string ::1
Setup notify_push (attempt 1/5)
✓ redis is configured
✓ push server is receiving redis messages
✓ push server can load mount info from database
✓ push server can connect to the Nextcloud server
✓ push server is a trusted proxy
✓ push server is running the same version as the app
configuration saved
Scanning AppData for files

Who will answer this?
You may start another ssh session for further investigation.
In future times you may get accustomed using a terminal multiplexer (tbh, I’m even not using it at first attempt).
Good luck.

Good news! An hour or so later, the restore finished and it seems things are running! I’ll now proceed upgrading back to the current version.

The only remaining issue is that letsencrypt won’t issue me a new SSL certificate because it can’t reach my box. This was actually how I borked my NCP initially, because I was trying to upgrade to a newer certbot version.

If you have any advice how to best upgrade certbot to a more recent version, that’d be great. I had done that a few months ago and it fixed my SSL renewal issues, but don’t remember what I did and screwed up when trying it again after I somehow ended up with the old certbot again.

1 Like

Sorry, I never did it myself, but you may find reading the ncp-docs helpfull, their discussions and links, wwe writes very nice faqs. Keep in mind this is a new topic and it is mostly network.

2 Likes

Ok, I’m back to square one… when I was going through upgrade after upgrade in order to get my successfully restored nextcloud instance up to date, I ended up with the box being unreachable via SSH and all other means. After a bunch of attempts to fix it, I decided to go back and do exactly what I had done before: Flash NCP v1.54.3, restore my old backup and config from Aug 2024, and then create new backups as I go through the upgrades.

However, I am now getting the following error during the very same restore that worked before (this is when trying to restore the NCP config):

```
Restoring old ‘/var/www/nextcloud/data’ to ‘/var/www/nextcloud/data’…
restore database…
No datadir found in backup
Your data directory is invalid.
Ensure there is a file called “.ocdata” in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:167
Stack trace:
#0 /var/www/nextcloud/console.php(99): OC\Console\Application->loadCommands()
#1 /var/www/nextcloud/occ(11): require_once(‘…’)
#2 {main}Cleanup…
```

When trying to do the full ncp-restore, I get a similar error:

```
Running nc-restore
check free space…
extracting backup file /mnt/backups/nextcloud-bkp_20240820_1724156326.tar.gz…
restore files…
Restoring old ‘/var/www/nextcloud/data’ to ‘/var/www/nextcloud/data’…
restore database…
No datadir found in backup
Your data directory is invalid.
Ensure there is a file called “.ocdata” in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:167
Stack trace:
#0 /var/www/nextcloud/console.php(99): OC\Console\Application->loadCommands()
#1 /var/www/nextcloud/occ(11): require_once(‘…’)
#2 {main}Cleanup…
Done. Press any key…
```

It’s true that there is no .ocdata file in the data directly, but I don’t know why it may be missing or how to fix it:

```
ncpadmin@nextcloudpi:/mnt/ncdata$ sudo ls ./data/
[sudo] password for ncpadmin:
appdata_oc1ocz2drpkc index.html ncp nextcloud.log nils
files_external lindsay ncp-update-backups nextcloud.log.1 tmp
ncpadmin@nextcloudpi:/mnt/ncdata$
```

Grateful for any advice!

I’ve solved this by fixing some permissions, making the .ocdata file accessible, and then trying again. After that, MariaDB crashed during the restore, so I made some changes to its memory config suggested by ChatGPT, did a successful restore, and then started the upgrade process again but more carefully. I first upgraded NCP to the latest version before cycling through the major Nextcloud versions, making backups in between. It all worked out.

Thanks for all the help! I learned a lot to avoid this in the future.