Files in the /opt/alert/rules directory are generated from the .alertrules index.
The best method will be a periodic backup of this index using, for example, a script:
/usr/share/elasticsearch/utils/small_backup.sh
or directly elasticdump:
NODE_TLS_REJECT_UNAUTHORIZED=0 usr/share/kibana/elasticdump/elasticdump --input=https://user:password@127.0.0.1:9200/.alertrules --output=./alertrules.json --type=data
We can restore from the backup in the following way:
NODE_TLS_REJECT_UNAUTHORIZED=0 usr/share/kibana/elasticdump/elasticdump --input=./alertrules.json --output=https://user:password@127.0.0.1:9200/.alertrules--type=data