# 📦 Balena Device Data Copier
This script helps securely **copy data from BalenaOS devices running in production mode** to a local server using `rsync` over an SSH tunnel created with the Balena CLI.
It is designed for use in the **MIRA Project**, to collect network measurement data from deployed Balena devices.
---
## âś… Requirements
Before running this script, ensure you have the following:
### 1. Balena CLI
Install the Balena CLI by following the official instructions:
đź”—
balena.io
After installation, make sure `balena` is accessible in your terminal by running:
```bash
balena --version
```
---
### 2. SSH Key Setup (for Production Mode Access)
To access Balena devices in **production mode**, you must manually set up a private/public key pair and register it with your Balena account.
#### a. Generate an SSH key (if you don't have one)
```bash
ssh-keygen -t rsa -b 4096 -f ~/.ssh/mykey
```
This will generate:
- A private key: `~/.ssh/mykey`
- A public key: `~/.ssh/mykey.pub`
> ⚠️ Do **NOT** share your private key. Ensure it's readable only by you:
>
> ```bash
> chmod 600 ~/.ssh/mykey
> ```
#### b. Add the SSH Public Key to device
1. Follow
docs.balena.io on how to add ssh_key to the device(either before / after provison)
---
## 📦 Docker Volume Mapping (Required Setup on Device)
To ensure the script works correctly, your Balena application should define **named Docker volumes** in its `docker-compose.yml` file. These volumes must be mounted to the `/reports` directory (or other consistent paths) inside your containers to persist data.
### Example
```yaml
services:
container_1:
build: ./container_1
volumes:
- 'data_volume_1:/reports'
container_2:
build: ./container_2
volumes:
- 'data_volume_2:/reports'
volumes:
data_volume_1:
data_volume_2:
```
> 📝 This ensures that all measurement data saved in `/reports` inside containers is also accessible from `/var/lib/do …