> For the complete documentation index, see [llms.txt](https://prosbcdocs.telcobridges.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://prosbcdocs.telcobridges.com/tmedia-documentation/platforms-and-hardware/automatic-text-cdr-retrieval.md).

# Automatic Text CDR Retrieval

This procedure describes how to configure a Tmedia and [ProSBC](https://telcobridges.com/sbc/products/prosbc/) to send its Call Detail Records (CDR) files to a remote server automatically and perform daily (or monthly) file archives.

## Overview

The *tbcopycdr* script supports the following features:

* Move cdr files from TMG\_CDR\_DIR to TMG\_TEMP\_DIR
* Send files to a remote server
* Move sucessfully sent files (rename to .sent.gz) from TMG\_TEMP\_DIR to TMG\_ARCHIVE\_DIR (ARCHIVE=true)
* Rename sucessfully sent files (.sent.gz) in TMG\_TEMP\_DIR (ARCHIVE=false; ERASE\_AFTER\_SEND=false)
* Delete sucessfully sent files from TMG\_TEMP\_DIR (ARCHIVE=false; ERASE\_AFTER\_SEND=true)
* If a file failed to be sent to remote server, it is kept in TMG\_TEMP\_DIR until it is successfully sent

The *tbarchivecdr* script creates a gzip tar archive with all gz files copied by *tbcopycdr* in TMG\_ARCHIVE\_DIR

* Change directory to TMG\_ARCHIVE\_DIR
* Create a temporary folder with the current date (for example: 2016-01-30)
* Sleep for 90 second
* Move all \*.gz files and $TMG\_TEMP\_DIR/$LOG\_FILE to this folder
* Archive the folder in a gzipped tar file (cdr\_2016\_01\_30\_$hostname.tgz)

## Configuration

The script is configured with **user variables**.

* *CONFIG\_FILE*: Configuration file name and location. By default, it is set to /root/tbcopycdr.cfg CONFIG\_FILE=/root/tbcopycdr.cfg

*tbcopycdr.cfg* file example: TMG\_TEMP\_DIR=/home/tbcopycdr TMG\_CDR\_DIR=/lib/tb/toolpack/setup/12358/cdr\_logs ARCHIVE=true TMG\_ARCHIVE\_DIR=/lib/tb/toolpack/setup/12358/cdr\_archive ARCHIVE\_MAX\_DAYS=180 REMOTE\_HOST=192.168.101.170 REMOTE\_PORT=22 REMOTE\_DIR=/root/cdr\_backups REMOTE\_USER=root

The configuration file can redefine any of the following user variables. To see the default variables: head -n 50 /usr/bin/tbcopycdr

* *TMG\_CDR\_DIR*: Tmedia directory where the [CDR](https://github.com/telcobridges-main/tmedia-wiki/tree/main/reference/concepts/text-call-detail-records/README.md) are located. Default is /lib/tb/toolpack/setup/12358/cdr\_logs TMG\_CDR\_DIR=/lib/tb/toolpack/setup/12358/cdr\_logs
* *REMOTE\_HOST* : Remote hostname or Ip address. Remote host copy is disabled by default. REMOTE\_HOST=10.10.10.10
* *REMOTE\_PORT* : Remote host ssh port. REMOTE\_PORT=22
* *REMOTE\_DIR* : Remote directory where to copy the backup files (/root/backup by default) REMOTE\_DIR=/root/backup
* *REMOTE\_USER* : Remote host login user. REMOTE\_USER=root
* *CONNECT\_TIMEOUT* : *scp* connection timeout CONNECT\_TIMEOUT=10
* *ARCHIVE*: true or false. If set to true, move successfully sent files (rename to .sent.gz) from TMG\_TEMP\_DIR to TMG\_ARCHIVE\_DIR. Default is false. ARCHIVE=false
* *TMG\_ARCHIVE\_DIR*: Directory where the cdrs are moved if ARCHIVE=true TMG\_ARCHIVE\_DIR=/lib/tb/toolpack/setup/12358/cdr\_archive
* *ARCHIVE\_MAX\_DAYS*: Define how many days the archive file (.tgz) should be kept in TMG\_ARCHIVE\_DIR. This user variable is used by *tbarchivecdr* only.

1. Assign no value to disable ARCHIVE\_MAX\_DAYS=

* *ERASE\_AFTER\_SEND*: Take effect only if ARCHIVE is false. If ERASE\_AFTER\_SEND is true, erase file from TMG\_TEMP\_DIR, else, rename and keep files in working directory. ERASE\_AFTER\_SEND=false

Note: If you set ERASE\_AFTER\_SEND to false, the CDR text file will be available in the /home/telcobridges/cdr/ directory and renamed \*.gz.already\_send.

## Remote Server Copy

You must create an SSH key pair and copy it to the remote server, if the remote server copy is configured. This will enable copy the backup files to the remote host without asking for a password. Follow the instructions here:

* [Password-less SSH](https://github.com/telcobridges-main/tmedia-wiki/tree/main/tmedia/operations/password-less-ssh/README.md)

## Troubleshooting

### Test

* Run the tbcopycdr script with the -v option tbcopycdr -v

If no errors are seen in the shell, your configuration is correct. In addition, you should have a hello\_world.log file on the remote host.

### Log File

Transfer results are written in $TMG\_TEMP\_DIR/$LOG\_FILE

## Schedule the Scripts

* Create a new crontab on the [Tmedia](https://telcobridges.com/media-gateways/products/tmedia-gateways/) crontab -e
* Add new lines with the cron configuration

***tbcopycdr***:

| Frequency                | Cron Configuration                                 |
| ------------------------ | -------------------------------------------------- |
| Every 10 minutes         | `*/10 * * * * /usr/bin/tbcopycdr > /dev/null 2>&1` |
| hourly (top of the hour) | `0 * * * * /usr/bin/tbcopycdr > /dev/null 2>&1`    |
| daily (midnight)         | `0 0 * * * /usr/bin/tbcopycdr > /dev/null 2>&1`    |

***tbarchivecdr***:

| Frequency              | Cron Configuration                                   |
| ---------------------- | ---------------------------------------------------- |
| daily\@23h59           | `59 23 * * * /usr/bin/tbarchivecdr > /dev/null 2>&1` |
| weekly (sunday\@23h59) | `59 23 * 7 * /usr/bin/tbarchivecdr > /dev/null 2>&1` |

Cron table example for a cdr copy to an external server every 10 minutes with a daily archive of all the transmitted files:

* /10 \* \* \* \* /usr/bin/tbcopycdr > /dev/null 2>&1 59 23 \* \* \* /usr/bin/tbarchivecdr > /dev/null 2>&1


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://prosbcdocs.telcobridges.com/tmedia-documentation/platforms-and-hardware/automatic-text-cdr-retrieval.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
