Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonycoders committed Jun 17, 2020
1 parent 2169ab4 commit 73bcd2e
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:latest

LABEL maintainer="Sorena Sarabadani <[email protected]>"

ENV MC_HOST_SOURCE **None**
ENV MC_HOST_DESTINATION **None**
ENV SCHEDULE **None**

ADD . .

RUN sh setup.sh && rm setup.sh

CMD ["sh", "run.sh"]
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg
[license-url]: https://github.com/fandoghpaas/minio-backup-s3/blob/master/LICENSE

[docker-image]: https://img.shields.io/docker/pulls/fandoghpaas/minio-backup-s3.svg
[docker-url]: https://hub.docker.com/r/fandoghpaas/minio-backup-s3/

# MinIO Backup S3
`minio-backup-s3` is a service giving you ability to mirror entities from `SOURCE OBJECT STORAGE` to `DESTINATION OBJECT STORAGE`.

## Docker

```sh
$ docker run -e MC_HOST_SOURCE=https://<Access Key>:<Secret Key>@<YOUR-S3-ENDPOINT> -e MC_HOST_DESTINATION=https://<Access Key>:<Secret Key>@<YOUR-S3-ENDPOINT> fandoghpaas/minio-backup-s3:<IMAGE_VERSION>
```


## [Fandogh PaaS](https://docs.fandogh.cloud) Manifest
Copy below manifest in a YAML file and enter `fandogh service apply -f <FILE_NAME>.yml`
```
kind: InternalService
name: minio-backup
spec:
image: _/fandoghpaas/minio-backup-s3:1.0.0
image_pull_policy: Always
env:
- name: MC_HOST_SOURCE
value: http://<Access Key>:<Secret Key>@<source-minio-service-name>
- name: MC_HOST_DESTINATION
value: http://<Access Key>:<Secret Key>@<destination-minio-service-name>
```

## Variable Table

> **Before deployment** value of `variables` mentioned in this table should be overwritten with values of your choice.
|Variable | Description |
|--- |--- |
|**MC_HOST_SOURCE** | Choose source MinIO endpoint url
|**MC_HOST_DESTINATION** | Choose destination MinIO endpoint url
|**SCHEDULE** | backup schedule time for cronjob, see explanations below


## SCHEDULE
You can set the `SCHEDULE` environment variable like `-e SCHEDULE="@daily"` or `-e SCHEDULE="0 0 */4 * * *"` to run the backup automatically.

> If you don't enter SCHEDULE env, container will perform its actions only one time and terminate!
More information about the scheduling can be found [here](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules).

29 changes: 29 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /bin/sh

set -e

if [ "${MC_HOST_SOURCE}" == "**None**" ]; then
echo "Error: You did not set the MC_HOST_SOURCE environment variable."
exit 1
fi

if [ "${MC_HOST_DESTINATION}" == "**None**" ]; then
echo "Error: You did not set the MC_HOST_SOURCE environment variable."
exit 1
fi

mirror_s3 () {
SOURCE_STORAGE=$1
DESTINATION_STORAGE=$2

echo "Mirroring buckets from ${SOURCE_STORAGE} to ${DESTINATION_STORAGE}..."

./mc mirror SOURCE DESTINATION

if [ $? != 0 ]; then
>&2 echo "Error in migarating files from ${SOURCE_STORAGE} to ${DESTINATION_STORAGE}!"
fi

}

mirror_s3 $MC_HOST_SOURCE $MC_HOST_SOURCE
9 changes: 9 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/sh

set -e

if [ "${SCHEDULE}" = "**None**" ]; then
sh backup.sh
else
exec go-cron "$SCHEDULE" /bin/sh backup.sh
fi
21 changes: 21 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /bin/sh

# exit if a command fails
set -e

apk update

#install minio mc
apk add wget
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
apk del wget

# install go-cron
apk add curl
curl -L --insecure https://github.com/odise/go-cron/releases/download/v0.0.6/go-cron-linux.gz | zcat > /usr/local/bin/go-cron
chmod u+x /usr/local/bin/go-cron
apk del curl

# cleanup
rm -rf /var/cache/apk/*

0 comments on commit 73bcd2e

Please sign in to comment.