Skip to content

Commit fd07d8e

Browse files
authored
Merge pull request #39 from jan-brinkmann/Transfer-via-SCP
Transfer via scp
2 parents 16ee615 + 0e9095b commit fd07d8e

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM ubuntu:18.04
22

3-
RUN apt-get update && apt-get install -y --no-install-recommends curl cron ca-certificates unzip
3+
RUN apt-get update && apt-get install -y --no-install-recommends curl cron ca-certificates openssh-client unzip
44
RUN rm -rf /var/lib/apt/lists/*
55

66
# Install awscliv2 https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ But for the sake of example, to finish the restore for the above Grafana setup,
9090
1. Depending on the Grafana version, [you may need to set some permissions manually](http://docs.grafana.org/installation/docker/#migration-from-a-previous-version-of-the-docker-container-to-5-1-or-later), e.g. `sudo chown -R 472:472 /var/lib/docker/volumes/bla-bla/_data`.
9191
1. Start Grafana back up, with `docker-compose start dashboard`. Your Grafana instance should now have travelled back in time to its latest backup.
9292

93+
### Backing up to remote host by means of SCP
94+
95+
You can also upload to your backups to a remote host by means of secure copy (SCP) based on SSH. To do so, [create an SSH key pair if you do not have one yet and copy the public key to the remote host where your backups should be stored.](https://foofunc.com/how-to-create-and-add-ssh-key-in-remote-ssh-server/) Then, start the backup container by setting the variables `SCP_HOST`, `SCP_USER`, `SCP_DIRECTORY`, and provide the private SSH key by mounting it into `/ssh/id_rsa`.
96+
97+
In the example, we store the backups in the remote host folder `/home/pi/backups` and use the default SSH key located at `~/.ssh/id_rsa`:
98+
99+
```yml
100+
version: "3"
101+
102+
services:
103+
104+
dashboard:
105+
image: grafana/grafana:7.4.5
106+
volumes:
107+
- grafana-data:/var/lib/grafana # This is where Grafana keeps its data
108+
109+
backup:
110+
image: futurice/docker-volume-backup
111+
environment:
112+
SCP_HOST: 192.168.0.42 # Remote host IP address
113+
SCP_USER: pi # Remote host user to log in
114+
SCP_DIRECTORY: /home/pi/backups # Remote host directory
115+
volumes:
116+
- grafana-data:/backup/grafana-data:ro # Mount the Grafana data volume (as read-only)
117+
- ~/.ssh/id_rsa:/ssh/id_rsa:ro # Mount the SSH private key (as read-only)
118+
119+
volumes:
120+
grafana-data:
121+
```
122+
93123
### Triggering a backup manually
94124

95125
Sometimes it's useful to trigger a backup manually, e.g. right before making some big changes.
@@ -209,6 +239,9 @@ Variable | Default | Notes
209239
`AWS_SECRET_ACCESS_KEY` | | Required when using `AWS_S3_BUCKET_NAME`.
210240
`AWS_DEFAULT_REGION` | | Optional when using `AWS_S3_BUCKET_NAME`. Allows you to override the AWS CLI default region. Usually not needed.
211241
`AWS_EXTRA_ARGS` | | Optional additional args for the AWS CLI. Useful for e.g. providing `--endpoint-url <url>` for S3-interopable systems, such as DigitalOcean Storage.
242+
`SCP_HOST` | | When provided, the resulting backup file will be uploaded by means of `scp` to the host stated.
243+
`SCP_USER` | | User name to log into `SCP_HOST`.
244+
`SCP_DIRECTORY` | | Directory on `SCP_HOST` where backup file is stored.
212245
`GPG_PASSPHRASE` | | When provided, the backup will be encrypted with gpg using this `passphrase`.
213246
`INFLUXDB_URL` | | When provided, backup metrics will be sent to an InfluxDB instance at this URL, e.g. `https://influxdb.example.com`.
214247
`INFLUXDB_DB` | | Required when using `INFLUXDB_URL`; e.g. `my_database`.

src/backup.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ if [ ! -z "$AWS_GLACIER_VAULT_NAME" ]; then
105105
TIME_UPLOADED="$(date +%s.%N)"
106106
fi
107107

108+
if [ ! -z "$SCP_HOST" ]; then
109+
info "Uploading backup by means of SCP"
110+
echo "Will upload to $SCP_HOST:$SCP_DIRECTORY"
111+
TIME_UPLOAD="$(date +%s.%N)"
112+
scp -ro StrictHostKeyChecking=no -i /ssh/id_rsa $BACKUP_FILENAME $SCP_USER@$SCP_HOST:$SCP_DIRECTORY
113+
echo "Upload finished"
114+
TIME_UPLOADED="$(date +%s.%N)"
115+
fi
116+
108117
if [ -d "$BACKUP_ARCHIVE" ]; then
109118
info "Archiving backup"
110119
mv -v "$BACKUP_FILENAME" "$BACKUP_ARCHIVE/$BACKUP_FILENAME"

src/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ BACKUP_CRON_EXPRESSION="${BACKUP_CRON_EXPRESSION:-@daily}"
1010
AWS_S3_BUCKET_NAME="${AWS_S3_BUCKET_NAME:-}"
1111
AWS_GLACIER_VAULT_NAME="${AWS_GLACIER_VAULT_NAME:-}"
1212
AWS_EXTRA_ARGS="${AWS_EXTRA_ARGS:-}"
13+
SCP_HOST="${SCP_HOST:-}"
14+
SCP_USER="${SCP_USER:-}"
15+
SCP_DIRECTORY="${SCP_DIRECTORY:-}"
1316
BACKUP_FILENAME=${BACKUP_FILENAME:-"backup-%Y-%m-%dT%H-%M-%S.tar.gz"}
1417
BACKUP_ARCHIVE="${BACKUP_ARCHIVE:-/archive}"
1518
BACKUP_UID=${BACKUP_UID:-0}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: "3"
2+
3+
services:
4+
5+
dashboard:
6+
image: grafana/grafana:7.4.5
7+
volumes:
8+
- grafana-data:/var/lib/grafana # This is where Grafana keeps its data
9+
10+
backup:
11+
image: futurice/docker-volume-backup
12+
environment:
13+
SCP_HOST: 192.168.0.42 # Remote host IP address
14+
SCP_USER: pi # Remote host user to log in
15+
SCP_DIRECTORY: /home/pi/backups # Remote host directory
16+
volumes:
17+
- grafana-data:/backup/grafana-data:ro # Mount the Grafana data volume (as read-only)
18+
- ~/.ssh/id_rsa:/ssh/id_rsa:ro # Mount the SSH private key (as read-only)
19+
20+
volumes:
21+
grafana-data:

0 commit comments

Comments
 (0)