Backup and recovery
For full backup and recovery to work you will need the following data:
- control module
- MongoDB databases (
account,control) - SSDB databases (
actions,hb,notify,stat)
All of the backup methods create an archive in a user's current directory. Before executing the command, you must make sure that there is enough free space in the current directory to save the archive.
Control module
Backup
Archive control module data except *.pid и *.log files.
#!/usr/bin/env bash
tar -czf /backup/altcraft-$(date +%F).tar.gz /opt/altcraft --exclude=*.pid --exclude=*.log
Recovery
Unpack the archive back on its place and restart control module.
#!/usr/bin/env bash
/opt/altcraft/akd restart
To restore the control module from a backup copy on a new server, you must first configure the environment necessary for the module to operate
MongoDB
Data backup methods have their own documentation.
https://docs.mongodb.com/v3.4/core/backups/
We recommend backing up using snapshots (see Back Up and Restore with Filesystem Snapshots). The method using snapshots allows you to save a lot of time when restoring "heavy" collections with a large number of indexes.
Backup
Dump all databases and collections with the help of mongodump utility.
Use compression (--gzip) if you need.
mongodump utility description.
https://docs.mongodb.com/manual/reference/program/mongodump/
#!/usr/bin/env bash
mongodump --host 127.0.0.1 --port 27017 --gzip --archive=/backup/mongodb-control-$(date +%F).tar.gz
mongodump --host 127.0.0.1 --port 27018 --gzip --archive=/backup/mongodb-account-$(date +%F).tar.gz
Recovery
Recower the data with mongorestore and restart systemd services.
mongorestore utility description.
https://docs.mongodb.com/manual/reference/program/mongorestore/
#!/usr/bin/env bash
mongorestore --host 127.0.0.1 --port 27017 --gzip --arcdhive=/backup/mongodb-control-2019-06-01.tar.gz
mongorestore --host 127.0.0.1 --port 27018 --gzip --arcdhive=/backup/mongodb-account-2019-06-01.tar.gz
systemctl restart mongod-control
systemctl restart mongod-account
SSDB
We recommend backing up using snapshots and then moving all data from the snapshot to an archive. Importing and exporting keys in large SSDB databases can take up to several days. Databases structure example.
/var/lib/ssdb
├── actions
│ ├── data
│ └── meta
├── hb
│ ├── data
│ └── meta
├── notify
│ ├── data
│ └── meta
└── stat
├── data
└── meta
Backup
Archive catalogues, containing data and meta.
#!/usr/bin/env bash
tar -czf /backup/ssdb-actions-$(date +%F).tar.gz /var/lib/ssdb/actions
tar -czf /backup/ssdb-hb-$(date +%F).tar.gz /var/lib/ssdb/hb
tar -czf /backup/ssdb-notify-$(date +%F).tar.gz /var/lib/ssdb/notify
tar -czf /backup/ssdb-stat-$(date +%F).tar.gz /var/lib/ssdb/stat
Recovery
Unpack the archive and restart systemd services.
#!/usr/bin/env bash
systemctl restart ssdb-actions
systemctl restart ssdb-hb
systemctl restart ssdb-notify
systemctl restart ssdb-stat