.. _storage-migration: Migrate Data to Another Disk =========================================== High disk load may lead to delays in event arrivals. In severe cases, it might result in complete inoperability of FindFace Multi. One of the means for reducing the disk load is to migrate the FindFace Multi data storages to another disk. .. rubric:: In this section: .. contents:: :local: .. _prepare-disk: Prepare Disk -------------------- To prepare a disk for the data migration, do the following: #. Create a new mount point (``/mnt/ffdata`` in our example). .. code:: sudo mkdir /mnt/ffdata sudo chown ntech:ntech /mnt/ffdata #. Create a partition. .. code:: sudo parted /dev/sdb mklabel gpt mkpart primary ext4 1MiB 100% q sudo mkfs.ext4 /dev/sdb1 #. Learn the UUID of the partition (``sdb1`` in our example). .. code:: sudo blkid | grep sdb1 /dev/sdb1: LABEL="data" UUID="0638ebe0-853e-43ea-8f35-bfae305695d1" TYPE="ext4" PARTUUID="8cebaacc-77d7-4757-b4c6-14147e92646c" #. Add the partition to fstab to make it automatically mount on booting. .. code:: sudo vi /etc/fstab ------------ #DATA mount UUID=0638ebe0-853e-43ea-8f35-bfae305695d1 /mnt/ffdata/ ext4 auto,user,rw 0 2 ------------- #. Mount all the filesystems. .. code:: sudo mount -a Migrate Photo Storage ----------------------------- To migrate the FindFace Multi photo storage, do the following: #. Stop the ``findface-security`` service to prevent the data loss. .. code:: sudo systemctl stop findface-security #. By default, the photo data are stored at ``/var/lib/``. Migrate the photo storage to the :ref:`new disk `. .. code:: sudo cp -ax /var/lib/findface-security/ -R /mnt/ffdata/ sudo rm -r /var/lib/findface-security/ sudo cp -ax /var/lib/ffupload/ -R /mnt/ffdata/ sudo rm -r /var/lib/ffupload/ #. Create symbolic links for the new directories. .. code:: sudo ln -s /mnt/ffdata/findface-security/ /var/lib/ sudo ln -s /mnt/ffdata/ffupload/ /var/lib/ #. Ensure that the rights are correctly assigned. .. code:: sudo chown ntech:ntech /mnt/ffdata/findface-security/ #. Start the ``findface-security`` service. .. code:: sudo systemctl start findface-security Migrate Main Database (PostgreSQL) ------------------------------------ To migrate the PostgreSQL database, do the following: #. Stop the ``findface-security``, ``pgbouncer``, and PostgreSQL services. .. code:: sudo systemctl stop findface-security.service pgbouncer.service postgresql.service postgresql@10-main.service #. On the :ref:`new disk `, create a directory for the database. .. code:: sudo mkdir -p /mnt/ffdata/some_directory/db #. Migrate the database to the new directory. .. code:: sudo mv /var/lib/postgresql /mnt/ffdata/some_directory/db #. Create a symlink to the new directory. .. code:: sudo ln -s /mnt/ffdata/some_directory/db/postgresql /var/lib/postgresql #. Start the PostgreSQL, ``pgbouncer``, and ``findface-security`` services. .. code:: sudo systemctl start postgresql.service postgresql@10-main.service pgbouncer.service sudo systemctl start findface-security.service