Change root directory

I am using a hetzner VPS with hestia and attached volume. I do have one domain which is very data consuming. And i would like to set it’s root directory to the attached volume. I am not sure what is the best way to do? Should i mount the volume just to sub-directory of the root directory. And then advice hestia to use sub-directory? Or can i use a symlink? what is the best approach? Or can i change the root directory for single domain in hestia?

if you are fine with using the attached storage only for that single user, I’d suggest to mount it as /home/<youruser>
you can have an entry in /etc/fstab for that then and it should be reboot proof.
obviously you want to mount that storage elsewhere temporarily and move all data in there before mounting it at it’s final spot. and stop webserver/mariadb during the move to ensure data consistency…

also keep in mind the conf dirs have an immutable bit set, so you want to handle that accordingly :wink:

2 Likes

I use symlinks like this:

#!/bin/bash
source /opt/nm-bin/functions.sh

#compruebo que lo corre root
comoroot

maxargs 1 $#

#compruebo que haya parametro
if [ -z “$1” ]; then
echo “Debes introducir el usuario que quieres mover.”
echo “sintaxis: $0 usuario”
echo “Ejemplo: $0 ccprocura.es”
echo
ls /home/ --color=“auto”
echo
exit 1
else
usuario=$1
fi

origen=“/home/$usuario”
destino=“/home2/$usuario”

origenb=“$origen/”
destinob=“$destino/”

abortar=“false”

#compruebo que el origen no sea un enlace simbolico
if [ -h $origen ]; then
error “El origen es un symbolik link”
abortar=“true”
fi

#compruebo que el origen es un directorio
if [ -d $origen ]; then
msg “El directorio de origen existe.”

    else
    error "El directorio de origen no existe!"
    echo "Puede deberse a que el cliente $1 no haya sido creado o que hayas introducido mal el usuario."
    abortar="true" 
    fi

#compruebo que no haya una migracion anterior
if [ -d $destino ]; then
error “¡El directorio de destino ya existe! ¡Aborto!”
echo “$destino”
abortar=“true”

    fi

#Si ha habido errores criticos aborto
if [ “$abortar” == “true” ]; then
exit 1
fi

#todo OK: Realizo la operacion.

#Para evitar inconsistencias paro servicios de correo

size=$(du -hs $origen | cut -f1)
msg “Se moverán $size de datos de $origen a $destino”
msg “Suspendo todos los servicios del usuario: $usuario”

#/usr/local/hestia/bin/v-suspend-mail-domains $usuario
#v-suspend-user USER [RESTART]
#v-suspend-user $1 yes
/usr/local/hestia/bin/v-suspend-user $usuario

    msg "Creando directorio: $destino"
    mkdir $destino
    msg "Moviendo todos los servicios: DNS CORREO WEB etc. a: $destino"
    rsync -alH $origenb $destino
    #cp -a $origenb $destinob

    msg "Preparo origen para borrarlo"
    chattr -i $origen/conf

    msg "Borrando los servicios: DNS CORREO WEB etc. del origen: $origen"
    rm -Rf $origen
    msg "Creando enlace origen-destino"
    # ojo la sintaxis de ln: ln source_file link_file
    ln -s $destino $origen

msg “Levantando la suspensión del usuario: $usuario”
#/usr/local/hestia/bin/v-unsuspend-mail-domains $usuario
#el yes es para reiniciar los servicios
/usr/local/hestia/bin/v-unsuspend-user $usuario yes

#aunque ya no se paran, es buena idea iniciarlos igualmente
#reinicio los servicios
msg “Iniciamos los servicios”
/usr/local/hestia/bin/v-list-sys-services | grep stopped | cut -d" " -f1 | xargs -I {}

#Lista de servicios activos
msg “Servicios del sistema:”
/usr/local/hestia/bin/v-list-sys-services

logwrite “$usuario movido de $origen a $destino - $size”

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.