Backup and migration of TVIP TMS

The tms_ctl command is used for backup and restore. It saves all platform data into one archive: PostgreSQL dumps, MongoDB archives and JWT tokens necessary for microservices operation.

Backup

Creating an archive:

sudo tms_ctl backup /backup/tms-backup.tar.gz

If no path is specified, the archive will be saved to /var/backups/tms/tms-backup-<timestamp>.tar.gz.

The archive includes:

  • dumps of tvip-tms, tvip-tms-audit and tvip-tms-vod databases;

  • dumps of MongoDB databases images and content;

  • JWT token values (access-token-secret, refresh-token-secret);

  • manifest.yaml file with archive metadata (creation date, tms_ctl version, list of components).

The command parameters allow you to exclude individual components from the archive:

  • --no-postgres - do not perform PostgreSQL backups;

  • --no-mongo - do not perform MongoDB backup;

  • --no-tokens - do not save JWT tokens.

Automatic backup

For regular backups, set up a cron job:

sudo tms_ctl backup --install-cron --keep-days 30 /backup/tms-backup.tar.gz

The --keep-days N parameter specifies the archive retention period: files older than N days are deleted automatically. The task is registered in /etc/cron.d/tms_ctl-backup, output of runs is written in /var/log/tms_ctl-backup.log.

By default, the task is executed daily at 03:00. The schedule can be set by the --schedule parameter accepting a standard cron string of five fields:

sudo tms_ctl backup --install-cron --schedule "30 2 * * *" --keep-days 30 /backup/tms-backup.tar.gz

Delete task:

sudo tms_ctl backup --uninstall-cron

Restoring

Warning

Restore overwrites the contents of existing databases and JWT tokens. Before executing, make sure that the archive is specific to that platform.

sudo tms_ctl restore /backup/tms-backup.tar.gz

The command will automatically:

  • terminates active connections to the restored PostgreSQL databases;

  • recreates databases and loads data from the archive into them;

  • restores MongoDB databases;

  • returns JWT tokens to the microservices configuration files.

The --no-postgres, --no-mongo and --no-tokens options allow you to restore only part of the archive.

By default, after restoring the tvip-tms base, the device.authkey value is reset to zero - this is necessary when migrating to another server, so that client devices pass binding again. If the archive is restored to the same stand and saving activations is mandatory, add the flag --no-reset-authkeys:

sudo tms_ctl restore --no-reset-authkeys /backup/tms-backup.tar.gz

Migration to another server

  1. On the new server, perform install TVIP TMS.

  2. Copy the archive from the old server:

    scp /backup/tms-backup.tar.gz username@host:/backup/
    
  3. On the new server, apply the archive:

    sudo tms_ctl restore /backup/tms-backup.tar.gz
    

Attention

To migrate devices without requiring a login and password, enable the Allow Quick Binding option in the provider settings.

If necessary, change the IP address of the TVIP TMS server or redirect DNS to the new address.

Manual procedures

The commands below are used in non-standard scenarios or as an alternative to tms_ctl backup / tms_ctl restore.

Creating a backup of PostgreSQL database

You can backup the database using the pg_dump utility:

pg_dump --no-owner  -U tvip-tms tvip-tms  >  /backup/tvip-tms.sql

Hint

With the --exclude-table-data parameter, you can exclude tables that do not require backup to reduce the backup file size and speed up the recovery process:

pg_dump --no-owner --exclude-table-data=device_stat_channel -U tvip-tms tvip-tms  >  /backup/tvip-tms.sql

Backup additional databases if necessary:

pg_dump --no-owner -U tvip-tms tvip-tms-audit >  /backup/tvip-tms-audit.sql
pg_dump --no-owner -U tvip-tms tvip-tms-vod >  /backup/tvip-tms-vod.sql

Copy the database backup using the scp utility:

scp /backup/tvip-tms.sql username@host:/backup/

Recovery from a PostgreSQL Database Backup

Ensure that the system meets the minimum TVIP TMS requirements.

Before installing TVIP TMS, you must install the database and restore the data from a backup.

Set and check that the locale selected is: [*] en_US.UTF-8 UTF-8. If necessary, add the locales you need.

sudo apt -y install postgresql

Create a database with the name tvip-tms and the user tvip-tms:

su -c "createuser tvip-tms && createdb -O tvip-tms tvip-tms" postgres

If necessary, create additional databases:

su -c "createdb -O tvip-tms tvip-tms-audit" postgres
su -c "createdb -O tvip-tms tvip-tms-vod" postgres

Change the postgres access settings:

sed -i /etc/postgresql/*/main/pg_hba.conf -e "s|local   all             all                                     peer|local   all             all                                     trust|"
sed -i /etc/postgresql/*/main/pg_hba.conf -e "s|host    all             all             127.0.0.1/32            md5|host    all             all             127.0.0.1/32            trust|"
sed -i /etc/postgresql/*/main/pg_hba.conf -e "s|host    all             all             127.0.0.1/32            scram-sha-256|host    all             all             127.0.0.1/32            trust|"
systemctl reload postgresql

Restore the database backup:

psql -U tvip-tms tvip-tms  < /backup/tvip-tms.sql

If necessary, restore additional databases as well:

psql -U tvip-tms tvip-tms-vod  < /backup/tvip-tms-vod.sql
psql -U tvip-tms tvip-tms-audit  < /backup/tvip-tms-audit.sql

Reset the value for auth key:

psql -U tvip-tms tvip-tms
update device set authkey = null;
\q

Install TVIP TMS.

Attention

To migrate devices without requiring a login and password, enable the Allow Quick Binding option in the provider settings.

If necessary, change the ip address of your TVIP TMS server or redirect DNS to a new TVIP TMS server.

Creating and restoring a MongoDB backup

Warning

Creating a backup copy of MongoDB database is mandatory if you need to migrate or create a backup copy of VOD database. Otherwise images associated with VOD database content (movie posters, screenshots of episodes, etc.) will be missing in the system after import.

Create a backup of the MongoDB database, using the mongodump utility:

mongodump --db images --gzip --archive > /mongoBackup/images.dump.gz

Install the MongoDB database on the new server:

apt install mongodb-org
systemctl start mongod.service
systemctl enable mongod.service

Restore the MongoDB backup, using the mongorestore utility:

mongorestore --gzip --archive=/mongoBackup/images.dump.gz

Note

If you need to save the statistics, save and restore a backup for the content database:

mongodump --db content --gzip --archive > /mongoBackup/content.dump.gz
mongorestore --gzip --archive=/mongoBackup/content.dump.gz