Nextcloud backup

I am trying to backup the nextcloud mysql database I have read to run the command:

"mysqldump --single-transaction -h [server] -u [username] -p [password] [db_name]> nextcloud-sqlbkp_date +"% Y% m% d " .bak "

I run the following command to find out which username is running my nextcloud installation:

“sudo mysql -u root -p”

“MariaDB [(none)]> SELECT User, Host, Password FROM mysql.user;”

I have found that the user is: “oc_rene”

But how do I find

  1. [server]
  2. [db_name]

As I will use in the command:

"mysqldump --single-transaction -h [server] -u [username] -p [password] [db_name]> nextcloud-sqlbkp_date +"% Y% m% d " .bak "

To backup?

Thanks in advance

If you run this line on the machine where mariadb is installed, you can omit the portion “-h [server]”

If you don’t have much databases on the machine, when you login mariadb and in the MariaDB prompt, type

show databases;

and make a wise guess on what you see.
If you see a long list, better ask the one who did the original setup.

Okay but what about password to the user Oc_rene? It is apparently a user nextcloud has created in the database during installation ?? But I can see I need password for the user “Oc_rene” to backup the database?

“” mysqldump --single-transaction -h [server] -u [username] -p [password] [db_name]> nextcloud-sqlbkp_date + “% Y% m% d” .bak "

It is also stated here:

“After you enter your root or administrator login for your database, the installer creates a special database user with privileges limited to the Nextcloud database. Then Nextcloud needs only the special Nextcloud database user, and drops the root dB login”

You can look up the according values in Nextclouds config.php which is located at /path/to/nextcloud/config/config.php

Thanks for the help :slight_smile: Backup must be:

/ Srv / dev disc-by-label Share / MyFiles

on my device, how should the line look like saving on that location?

“Mysqldump --single-transaction -h [server] -u [username] -p [password] [db_name]> nextcloud-sqlbkp_date +”% Y% m% d “.bak”?

I’m not nerd therefore I ask :slight_smile:

Now I’ve got a backup of the database to work with this command:

"mysqldump --single-transaction -h localhost -uoc_rene -pomjFBSjefCKWb4o8PR9KPxGAvgibQn nextcloud> / srv / dev-disk-by-tag-Share / Myfiles / ncdb_date +"% w " .sql "

So far so good !

I have tried to look at the different guides to how to restore from backup on the new server but can not find any explanation how to restore the user “Oc_rene” which is a user nextcloud made during the setup on the old installation?

I can not use it

“mysql -h [server] -u [username] -p [password] -e” DROP DATABASE nextcloud "

On the new installation, when the user “Oc_rene” is missing since it has not been restored?

Does your “new” server already has a database named “nextcloud” for you to drop?

if yes, use a user (could be root in mysql) to drop it. Or grant Oc_rene the privilege to drop database. (just wonder why the original admin didn’t do it, what to protect from?)

if no, skip this step.

BTW, on the “new” server, you need to create “new” user and grant it proper privileges. Lot of people will change those default name for the sake of security, But still lot of home router can be logged in by admin/admin. Just make sure you use the same set of id/pwd here and in config/config.php.

On the old installation we made a “root” user in mysql and did as in the guide:

I quote :

"You will need the root database login, or any administrator login that has permissions to create and modify databases, and then enter any name you want for your Nextcloud database.

After you enter your root or administrator login for your database, the installer creates a special database user with privileges limited to the Nextcloud database. Then Nextcloud needs only the special Nextcloud database user, and drops the root dB login. This user is named for your Nextcloud admin user, with an oc_ prefix, and then given a random password. The Nextcloud database user and password are written into config.php:"

But since it is NOT a full installation I do on the new server but a restore from a backup database, does nextcloud NOT make the user Oc_rene automatically? And there must be a security cause that you do not use the root user for the nextcloud database on the new installation?. Therefore, it would be beneficial to explain in your guide to how to restore the database to a new installation, how to restore previous users from the old installation as they are not existing on a clean installation. Does it make sense ?

You can create the according database user and the database with those commands (you will be prompted to enter the MySQL root password after the first command):

mysql -u root -p
create user '[DBUSER]'@'localhost' identified by '[DBPASSWORD]';
create database if not exists `[DBNAME]`;

Look up the according values of [DBUSER], [DBPASSWORD] and [DBNAME] in your /path/to/nextcloud/config/config.php

If there is also this line in your config.php, there are additional steps required:
'mysql.utf8mb4' => true,
You may find those additional steps here:

First of all, there is no “your guide”.

Never heard about “user Oc_rene” myself. You never mention where you inherit your copy of NC. We don’t ask just because it is 99.9999% irrelevant in general.

People helping out other people here are mostly volunteers. There are always paid service that serve one like a client. It is just not the way how forum works. People use more brain here.

NC is just a web application. It uses/manage database in the same way as wordpress, joomla, etc do. No magic.
ABC is:
one creates a database DEF in mysql, one creates a user GHI with password JKL in mysql, one grants GHI privileges to manage DEF in mysql. Then, one informs NC via config/config.php those name/key needed to utilize mysql. Clear?
Then, rename, copy, move, delete, … in whatever way you want. You want to keep the name Oc_rene? fine. You want to rename it? also fine. Just hold the ABC consist.

Thank you :slight_smile: It was not to be rude but just because it’s confusing when you’re new to linux :slight_smile: