Skip to main content

Replicate Nextcloud instance to another server

Destination:

Prepare

export user="user"
export src="(source host)"
export dst="(destination host)"
export path="/home/${user}/delme/${src}--${dst}/"
mkdir -p ${path}
chown -R ${user}:${user} /home/${user}/delme/
ls -la ${path}
namei -mo ${path}

Clean before bringing new stuff here (carefully here)

echo ${path}
ls -la ${path}
read -p "Correct path to clean?"
rm -i ${path}/*
ls -la ${path}

Source

Prepare

sudo su
export user="user"
export src="(source host)"
export dst="(destination host)"
export path="/home/${user}/delme/${src}--${dst}/"
export file="nextcloud.tgz.$(date +"%Y-%m-%d.%H%M")"
mkdir -p ${path}
ls -lahtr ${path}

Compress application directory (takes little time, coffee time)

tar -czvf ${path}/${file} /var/www/nextcloud/
ls -lahtr ${path}

Transfer file to the second instance

scp -v ${path}/${file} ${user}@${dst}:delme/${src}--${dst}/

Destination (continues):

Observe, that has been transferred correctly

ls -lahtr ${path}

Move aside current Nextcloud application instance before bring new one.

export dir_current="nextcloud.$(date +"%Y-%m-%d.%H%M")"
echo ${dir_current}
mv /var/www/nextcloud /var/www/${dir_current}
ls -latr /var/www

Extract it

# that is number one, not L letter
export file=$(ls -1 ${path}/nextcloud*)
echo ${file}
tar -xzvf ${file} -C /

After successful testing, remove old version, as they might occupy disk space.

ls -dlr /var/www/nextcloud*
du -h --max-depth=1 /var/www