Backup and restore
Stanag On Demand Server provides a set of maintenance utilities.
Backup and restore utilities can be found in the ./utils-backup directory.
When no specific instructions are provided, the scripts obtain configuration information from the .env file and config.json file located in the parent directory and the ./data directory. This info can be overridden by the explicit arguments provided to the scripts.
Prerequisites
Before you can effectively utilize the backup and restore scripts, it is essential to ensure that your system meets certain prerequisites.
Node.js Installation:
To run the provided backup and restore scripts, you must have Node.js (resent version, at least 16 or 18) installed on your system. Node.js provides the necessary environment to execute the scripts. If Node.js is not already installed on your system, you can download it from the official Node.js website. Follow the installation instructions for your specific operating system to set up Node.js.
Typically, the utilities are automatically copied to the server directory upon container startup, eliminating the need for any additional installation. In the event that you need to install the utility manually, please follow the instructions: installation instructions.
Backup
The backup script is designed to efficiently and reliably create backups of essential configurations and data. It performs the following actions:
- Binary export of a database's contents.
- Copy the ./data directory from the supplied stserver root (--serverDir).
- Copy the video assets directory files found in the (**--videoDir) folder.
- Copy the .env file.
- Create the info file with the backup information.
- Finally, the script bundles all the copied data and files into a TAR archive with the following structure:
├── TAR archive/
├── data/
├── db/
├── videos/
├── .env
├── info.json
Usage
cd utils-backup
./backup.sh
Note: Regularly schedule backups to ensure data integrity and security. Store backups in a secure location and consider encryption and off-site storage for added protection.
Restore
Restore script will perform the following actions:
- Import DB collections into the MongoDB
- Copy the ./data directory from the archive to the --serverDir folder.
- Copy the video assets from the archive to the --videoDir folder.
- Copy the .env file to the --serverDir folder.
Note, all collections that exist in the DB will be dropped!
Usage
cd utils-backup
./restore.sh --archive=/home/myuser/stserverArchive/stserverArchive-XXXX-XX-XX-XX-XX.tar
Note that if you're restoring an archive created on a different server, you may need to edit the .env file, as it may contain different names, addresses, and directories. Additionally, if your database has a different connection string, you'll need to provide it (using the --dbConnectionString argument) so that the restore utility can successfully restore the database.
You can restore only DB and the video assets, keeping the .env file and the data folder by providing --restoreDbAndAssetsOnly=true argument.
To apply these changes, please restart the server.
stserverBackup utility arguments
Short Command | Command | Description | Default |
---|---|---|---|
-m | --mode | Modes: backup / restore | backup |
-b | --backupTargetDir | Target folder for backup | |
-r | --archive | Archive source file | |
--videoDir | Video directory | ~/videos | |
--serverDir | Root folder for export / import. There may be one or more missions in that folder. | ../ | |
--dbConnectionStr | DB Url. | mongodb://localhost:27016/dbS2 | |
-d | --description | Backup note | |
--restoreDbAndAssetsOnly | Only restore DB and video assets | ||
--version | Show utility version | ||
--printUsage | Print this help message and exit | ||
-h | --help | Print this help message and exit |