Backing up CGrateS

This is super easy.

In my setup I use Redis as the DataDB which stores the Accounts, balances, etc, etc, and MySQL / MariaDB as the StorDB.

Backing up MySQL is just a matter of running mysqldump to dump all the data.

Backing up Redis, is just a matter of copying the /var/lib/redis/dump.rdb file, which is just a flat file that contains all the Redis data.

- name: Running StoreDB Dump on CGrateS
ansible.builtin.shell:
cmd: mysqldump cgrates > /tmp/cgrates_dump_{{ inventory_hostname }}_{{ ts }}.sql
chdir: /tmp/
become: True

- name: Fetch the dump from remote cgrates to local machine
fetch: src=/tmp/cgrates_dump_{{ inventory_hostname }}_{{ ts }}.sql dest={{ backup_path }}/ flat=yes

- name: Getting DataDB data
ansible.builtin.shell:
cmd: cp /var/lib/redis/dump.rdb /tmp/redis_dump_{{ inventory_hostname }}_{{ ts }}.rdb
chdir: /var/lib/redis/

- name: Fetch the DataDB dump from remote cgrates to local machine
fetch: src=/tmp/redis_dump_{{ inventory_hostname }}_{{ ts }}.rdb dest={{ backup_path }}/ flat=yes

Obviously you need to backup your .json config files, but to restore is just a matter of restoring the StorDB data with MySQL on the new machine, copying the Redis database into /var/lib/redis/dump.rdb on the new machine, and starting MySQL, Redis and CGrateS.

Leave a Reply

Your email address will not be published. Required fields are marked *