Clone Nextcloud

It is more an idea than a question.

Before every update, I’m afraid that it could go wrong and that I have to spend the next few hours looking for a solution. Honestly, it hasn’t happened to me very often, but there are a few cases here in the forum and actually I’m more concerned with the certainty that I can safely import the next update.

Wouldn’t it be practical to have a way to clone a complete Nextcloud instance on the web space?
So copy all files into a parallel or subordinate directory and either create a new database (will be difficult for most hosts to automate) or insert the tables with a new prefix into the original database.
Then the update could be tested with this clone.

Of course, the config.php of the clone would have to be adjusted and it may not be necessary to copy the user files.

It would be important that the clone script runs via PHP and does not require SSH access so that it can also be used by users who only have a web space account.

How do you like this idea?
Is it worth creating such a script, or does it even make sense to program the whole thing as an app?
Are there technical reasons why this might not work?

My skills are not sufficient to program such a script well enough. If I should try it, I would be dependent on ideas and help.

Greetings Kolja

1 Like

I think that is not important. I think for bigger installations it would not work. You need for test a similar environment.

Yes. But perhaps it is better to regularly backup and restore the nextclud installation. Than a upgrade-fail or a hdd-crash or stupidity in administration or usage does no matter.

1 Like

Thanks for your advice.
Can I ask a little more?

What role does the size of the installation play?
Although I suspect that such a script is needed by those who don’t have large clouds with many users.

Why isn’t it the same enviroment?
Except for the path and the prefix, everything is the same.

The backup & restore paths from the manual require SSH access and are therefore not suitable for many users.

BTW, the NC Updater already copies the data of the “old” installation into the data directory (without the user data files), is there a backup of the database somewhere?

edit: no!
Create backup: creates a backup of the existing code base in /updater-INSTANCEID/backups/nextcloud-CURRENTVERSION/ inside of the data directory (this does not contain the /data directory nor the database).

It is correct that users only with web space can not use the shell.
But why should a user with vps or home server use the inadequacy of a backup/restore or clone software of nextcloud installation only hosted on a webspace.

What role does the size of the installation play?

A webserver installation does not work. An with not more users a normal installation does not work, too.

Nothing beats regular backups but it’s easy to run a Nextcloud instance from a self-contained directory by using Docker Compose. With such a deployment, making an exact copy of the current instance is as easy as copying that directory. After that, you can try “risky” things and rest assured that you always can roll back to the previous state in no time. This method still needs file system access but it’s simple and it does the trick.

1 Like

I used SSH to copy my nextcloud installatin which I did via docker. (so no php solution). This script will copy a whole docker instance into a new one, serving on a new port number:


function help(){
        echo usage: $0 domain_to port [domain_from]
if [ "$1" == "--help" ]; then
  exit 0
if [ "$1" == "" ]; then
  echo "no domain to copy to"
  exit 0

if [ "$2" == "" ]; then                                                                                                                                                                                   
  echo "no port"
  exit 0

if [ "$3" == "" ]; then                                                                                                                                                                                   
  echo "no source"
  exit 0


TEMPLATE_PORT=$(grep :80 $BASE/$FROM/docker-compose.yml |cut -d" " -f 8|cut -d: -f 1)

echo copying from $FROM to $DOMAIN
echo using $DOCKERIMAGE

if [ -x $BASE/$DOMAIN/ ]; then
  echo "folder $BASE/$DOMAIN/ already exists!"
  exit 0

rsync -axX --info=progress2 $BASE/$FROM/ $BASE/$DOMAIN/ --exclude=volumes/html/data/*/files

sed -i "s|$FROM/volumes|$DOMAIN/volumes|g" $DOCKER_COMPOSE
echo '      - "'$DOMAIN':"' >> $DOCKER_COMPOSE

sed -i "s|$FROM|$DOMAIN|g" $BASE/$DOMAIN/volumes/html/config/config.php
mkdir -p $BASE/$DOMAIN/volumes/html/data
touch $BASE/$DOMAIN/volumes/html/data/.ocdata
docker-compose up -d
sleep 20
for u in some user names that are not needed in the new copy; do
  deleting user $u ...
  docker exec --user www-data $DOCKERIMAGE php occ user:delete "$u" 1>/dev/null
docker exec --user www-data $DOCKERIMAGE php occ files:scan --all

My only problem was then that the installed ONLYOFFICE document server still points to the URL of the old docker image. This is stored in the database, I copied, so I have to edit the database with:

docker exec next-deveclabsde_db_1 mysql nextcloud -p$MYSQL_ROOT_PASSWORD -e "update oc_appconfig set configvalue='' where appid='onlyoffice' AND configkey='DocumentServerUrl'"