Skip to content

Commit 1f156f8

Browse files
authored
Merge pull request #467 from databacker/scp-target
add scp support
2 parents 612e8b1 + e61141d commit 1f156f8

File tree

7 files changed

+1078
-9
lines changed

7 files changed

+1078
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mysql-backup is a simple way to do MySQL database backups and restores, as well
99
It has the following features:
1010

1111
* dump and restore
12-
* dump to local filesystem or to SMB server
12+
* dump to supported targets
1313
* select database user and password
1414
* connect to any container running on the same system
1515
* select how often to run a dump
@@ -96,7 +96,7 @@ __You should consider the [use of `--env-file=`](https://docs.docker.com/engine/
9696
* `DB_PASS`: password for the database
9797
* `DB_DUMP_INCLUDE`: names of databases to restore separated by spaces. Required if `SINGLE_DATABASE=true`.
9898
* `SINGLE_DATABASE`: If is set to `true`, `DB_DUMP_INCLUDE` is required and must contain exactly one database name. Mysql command will then run with `--database=$DB_DUMP_INCLUDE` flag. This avoids the need of `USE <database>;` statement, which is useful when restoring from a file saved with `SINGLE_DATABASE` set to `true`.
99-
* `DB_RESTORE_TARGET`: path to the actual restore file, which should be a compressed dump file. The target can be an absolute path, which should be volume mounted, an smb or S3 URL, similar to the target.
99+
* `DB_RESTORE_TARGET`: path to the actual restore file, which should be a compressed dump file. The target can be any valid backup target.
100100
* `DB_DEBUG`: if `true`, dump copious outputs to the container logs while restoring.
101101
* To use the S3 driver `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_DEFAULT_REGION` will need to be defined.
102102

docs/backup.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ to a target. That target can be one of:
66
* local file
77
* SMB remote file
88
* S3 bucket
9+
* SCP target
910

1011
## Instructions and Examples for Backup Configuration Options
1112

@@ -124,6 +125,7 @@ The value of the environment variable or CLI target can be one of three formats,
124125
* Local: If it starts with a `/` character or `file:///` url, it will dump to a local path. If in a container, you should have it volume-mounted.
125126
* SMB: If it is a URL of the format `smb://hostname/share/path/` then it will connect via SMB.
126127
* S3: If it is a URL of the format `s3://bucketname.fqdn.com/path` then it will connect via using the S3 protocol.
128+
* SCP: If it is a URL of the format `scp://user@hostname:/path` then it will connect via SCP.
127129

128130
In addition, you can send to multiple targets by separating them with a whitespace for the environment variable,
129131
or native multiple options for other configuration options. For example, to send to a local directory and an SMB share:
@@ -190,7 +192,21 @@ Note that if you have multiple S3-compatible backup targets, each with its own s
190192
or endpoint, then you _must_ use the config file. There is no way to distinguish between multiple sets of
191193
credentials via the environment variables or CLI flags, while the config file provides credentials for each
192194
target.
193-
195+
196+
##### SCP
197+
198+
If it is a URL of the format `scp://user@hostname/path` then it will connect via SCP. If you leave off the `user`
199+
i.e. `scp://hostname/path`, it will use the default ssh protocol for determining the user.
200+
The default port is `22`; you can override it with `scp://hostname:port/path`.
201+
202+
The `scp` implementation respects the following configuration:
203+
204+
* user's ssh config file, by default `$HOME/.ssh/config`
205+
* user's identity keys, by default `$HOME/.ssh/id_rsa`, `$HOME/.ssh/id_dsa`, etc.
206+
* override the directory for finding `config` and identity key files via `SSH_HOME`
207+
208+
As of this writing, the SCP implementation is basic and may not support all features of the SCP protocol.
209+
194210
#### Configuration File
195211

196212
The configuration file is the most flexible way to configure the dump target. It allows you to specify

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ require (
1313
github.com/docker/go-connections v0.4.0
1414
github.com/go-sql-driver/mysql v1.7.1
1515
github.com/johannesboyne/gofakes3 v0.0.0-20230506070712-04da935ef877
16-
github.com/moby/moby v28.3.3+incompatible
1716
github.com/robfig/cron/v3 v3.0.1
1817
github.com/sirupsen/logrus v1.9.3
1918
github.com/spf13/cobra v1.8.0
@@ -33,8 +32,12 @@ require (
3332
require (
3433
filippo.io/age v1.2.1
3534
github.com/InfiniteLoopSpace/go_S-MIME v0.0.0-20181221134359-3f58f9a4b2b6
35+
github.com/bramvdbogaerde/go-scp v1.5.0
3636
github.com/databacker/api/go/api v0.0.0-20250818102239-219c793f2151
3737
github.com/google/go-cmp v0.7.0
38+
github.com/kevinburke/ssh_config v1.2.0
39+
github.com/moby/go-archive v0.1.0
40+
github.com/pkg/sftp v1.13.9
3841
go.opentelemetry.io/otel v1.31.0
3942
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0
4043
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.31.0
@@ -43,17 +46,19 @@ require (
4346
)
4447

4548
require (
49+
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
4650
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
4751
github.com/containerd/errdefs v1.0.0 // indirect
4852
github.com/containerd/errdefs/pkg v0.3.0 // indirect
4953
github.com/containerd/log v0.1.0 // indirect
5054
github.com/distribution/reference v0.6.0 // indirect
5155
github.com/felixge/httpsnoop v1.0.3 // indirect
56+
github.com/gliderlabs/ssh v0.3.8 // indirect
5257
github.com/go-logr/logr v1.4.2 // indirect
5358
github.com/go-logr/stdr v1.2.2 // indirect
5459
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
60+
github.com/kr/fs v0.1.0 // indirect
5561
github.com/moby/docker-image-spec v1.3.1 // indirect
56-
github.com/moby/go-archive v0.1.0 // indirect
5762
github.com/moby/sys/atomicwriter v0.1.0 // indirect
5863
github.com/moby/sys/user v0.4.0 // indirect
5964
github.com/moby/sys/userns v0.1.0 // indirect

0 commit comments

Comments
 (0)