# Automatic data backup :id=top

> _Doc Ver:_ 1.0  
_App Ver:_ 1.0.0  
_Date:_ 11/29/2021

> This is the optional **dtb** tool, not an SA1 install pack. Do not look for it under `/sa1/install/`. Downloads still come from the historical tool host `112.74.80.60` (there is currently no LAN mirror under `/sa/tools/dtb/`).

Periodically scan the data directory that needs backup;  
using the config file on the USB disk, copy a set number of files from a set time range onto the USB disk.

## 1. Install :id=install

  * Download the pack:    
    http://112.74.80.60/tools/dtb/linux/amd64/latest/dtb_install.tar.gz
  * Copy the pack into the user's home directory;
  * Unpack
    In a shell, cd to the download directory and run:
    ```
        tar -xzvf dtb_install.tar.gz
    ```
  * Install
    ```
        cd dtb_install
        bash install.sh
    ```
  * Start on boot
    Add the following to the boot script. It takes effect after reboot.
    ```
        dtb_run start &
    ```

## 2. Configure backup parameters :id=configure 

  * Prepare a USB disk: format it as exFAT or FAT32;
  * Download the config file: 
    http://112.74.80.60/tools/dtb/linux/amd64/latest/dtb.cfg
  * Edit parameters: open the file in a text editor and follow the comments;
  ```
    Data directory
    Save directory
    Source file format
    File time range
  ```
  * Enable broadcast: set `process_udp_enable` to `1`. If the port clashes, change `process_udp_port`;
  * Finish: save `dtb.cfg`, copy it to the root of the formatted USB disk, then eject the disk safely. 


## 3. Backup :id=backup 

  * Receive backup broadcasts: use a UDP receiver on the port in `dtb.cfg` (`process_udp_port`);
  * Run the backup: plug the USB disk into the server that has dtb installed, watch progress on the UDP receiver, then unplug when done;
  * Inspect data: plug the USB disk into a PC and open the directory configured in the file to see the compressed copies.

## 4. Progress :id=monitor 

  The broadcast interface reports live status: errors, completion, and the file being processed.
  * Linux
  On any Linux host on the same network as the backup server, run:
  ```
    nc -l -u -k -p 7070

    7070: the port defined as "process_udp_port" in dtb.cfg;  
    -l: listen  
    -u: UDP  
    -k: keep the socket open after one datagram  
    -p: listen port  
  ```

## Change log :id=changelog

|Version|Date|Description|
|:--:|----|----------|
|1.0|11/29/2022|1. Help created for the new file format.|

------

[Top](#top)
