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 Security. One of the means for reducing the disk load is to migrate the FindFace Security data storages to another disk.

In this section:

Prepare Disk

To prepare a disk for the data migration, do the following:

  1. Create a new mount point (ffdata in our example).

    sudo mkdir /mnt/ffdata
    sudo chown ntech:ntech /mnt/ffdata
    
  2. Create a partition.

    sudo parted /dev/sdb
    mklabel gpt
    mkpart primary ext4 1MiB 100%
    q
    sudo mkfs.ext4 /dev/sdb1
    
  3. Learn the UUID of the partition (sdb1 in our example).

    sudo blkid | grep sdb1
    /dev/sdb1: LABEL="data" UUID="0638ebe0-853e-43ea-8f35-bfae305695d1" TYPE="ext4" PARTUUID="8cebaacc-77d7-4757-b4c6-14147e92646c"
    
  4. Add the partition to fstab to make it automatically mount on booting.

    sudo vi /etc/fstab
    ------------
    #DATA mount
    UUID=0638ebe0-853e-43ea-8f35-bfae305695d1 /mnt/ffdata/    ext4    auto,user,rw     0       2
    -------------
    
  5. Mount all the filesystems.

    sudo mount -a
    

Migrate Photo Storage

To migrate the FindFace Security photo storage, do the following:

  1. Stop the findface-security service to prevent the data loss.

    sudo systemctl stop findface-security
    
  2. Migrate the photo storage to the new disk.

    sudo -u ntech cp -pr /var/lib/ffsecurity/ /mnt/ffdata/
    sudo -u ntech cp -pr /var/lib/ffupload/ /mnt/ffdata/
    
  3. Create links for the new directories.

    sudo ln -s /mnt/ffdata/ffsecurity/ /var/lib/
    sudo ln -s /mnt/ffdata/ffupload/ /var/lib/
    
  4. Ensure that the rights are correctly assigned.

    sudo chown ntech:ntech /mnt/ffdata/ffsecurity/
    
  5. Start the findface-security service.

    sudo systemctl start findface-security
    

Migrate Main Database (PostgreSQL)

To migrate the PostgreSQL database, do the following:

  1. Learn the current database directory.

    postgres=# SHOW data_directory;
    
            data_directory
    ------------------------------
     /var/lib/postgresql/10/main
    
  2. Stop PostgreSQL.

    sudo systemctl stop postgresql
    
  3. Create a new directory that will hold the database and assign it to the ntech user.

    mkdir postgres_data_dir
    chown ntech postgres_data_dir
    
  4. Migrate the database and backup the old one.

    sudo rsync -av /var/lib/postgresql /test/postgres_data_dir/
    sudo mv /var/lib/postgresql/10/main /backups/pg_backup
    
  5. Substitute the directory in the PostgreSQL configuration file postgresql.conf.

    data_directory = '/test/postgres_data_dir/postgresql/10/main'
    
  6. Start PostgreSQL.

    sudo systemctl start postgresql
    
  7. Check if the directory has successfully been changed.

    postgres=# SHOW data_directory;
    
            data_directory
    --------------------------------------------
    /test/postgres_data_dir/postgresql/10/main