Skip to content

Commit d7964da

Browse files
committed
chore: Initialized project
0 parents  commit d7964da

File tree

7 files changed

+146
-0
lines changed

7 files changed

+146
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/workflows/docker.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Create and publish a Docker image
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
release:
7+
types:
8+
- created
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build-and-push-image:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v2
24+
25+
- name: Log in to the Container registry
26+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
27+
with:
28+
registry: ${{ env.REGISTRY }}
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Extract metadata (tags, labels) for Docker
33+
id: meta
34+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
35+
with:
36+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
37+
38+
- name: Build and push Docker image
39+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
40+
with:
41+
context: .
42+
push: true
43+
tags: ${{ steps.meta.outputs.tags }}
44+
labels: ${{ steps.meta.outputs.labels }}

.s3cfg

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[default]
2+
add_encoding_exts =
3+
add_headers =
4+
cache_file =
5+
cloudfront_host =
6+
default_mime_type = binary/octet-stream
7+
delay_updates = False
8+
delete_after = False
9+
delete_after_fetch = False
10+
delete_removed = False
11+
dry_run = False
12+
enable_multipart = True
13+
encoding = UTF-8
14+
encrypt = False
15+
expiry_date =
16+
expiry_days =
17+
expiry_prefix =
18+
follow_symlinks = False
19+
force = False
20+
get_continue = False
21+
gpg_command = /usr/bin/gpg
22+
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
23+
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
24+
gpg_passphrase =
25+
guess_mime_type = True
26+
human_readable_sizes = False
27+
ignore_failed_copy = False
28+
invalidate_default_index_on_cf = False
29+
invalidate_default_index_root_on_cf = True
30+
invalidate_on_cf = False
31+
list_md5 = False
32+
log_target_prefix =
33+
max_delete = -1
34+
mime_type =
35+
multipart_chunk_size_mb = 15
36+
preserve_attrs = True
37+
progress_meter = True
38+
proxy_host =
39+
proxy_port = 0
40+
put_continue = False
41+
recursive = False
42+
recv_chunk = 4096
43+
reduced_redundancy = False
44+
restore_days = 1
45+
send_chunk = 4096
46+
server_side_encryption = False
47+
simpledb_host =
48+
skip_existing = False
49+
socket_timeout = 300
50+
urlencoding_mode = normal
51+
use_https = True
52+
use_mime_magic = True
53+
verbosity = WARNING
54+
website_error =
55+
website_index = index.html
56+
signature_v2 = True

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM mongo:latest
2+
3+
RUN apt update
4+
RUN apt install python s3cmd -y
5+
6+
COPY backup.sh /backup.sh
7+
RUN chmod +x /backup.sh
8+
9+
COPY ./.s3cfg /root/.s3cfg
10+
11+
ENTRYPOINT [ "/backup.sh" ]

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2021 nitpum
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
IMAGE_NAME="nitpum/mongo-s3-backup"
2+
3+
build:
4+
docker build -t ${IMAGE_NAME} .

backup.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
BACKUP_FILE_NAME="$(date +%y-%m-%d_%H-%M-%S).gz"
4+
BACKUP_FILE_PATH="/tmp/$BACKUP_FILE_NAME"
5+
6+
echo "access_key=$S3_ACCESS_KEY" >> /root/.s3cfg
7+
echo "secret_key=$S3_SECRET_KEY" >> /root/.s3cfg
8+
echo "bucket_location=$S3_BUCKET_LOCATION" >> /root/.s3cfg
9+
echo "host_base=$S3_HOST_BASE" >> /root/.s3cfg
10+
echo "host_bucket=$S3_HOST_BUCKET" >> /root/.s3cfg
11+
echo "website_endpoint=$S3_WEBSITE_ENDPOINT" >> /root/.s3cfg
12+
13+
echo "Start mongodump..."
14+
15+
/usr/bin/mongodump --uri="$MONGO_URI" --gzip --archive="$BACKUP_FILE_PATH"
16+
17+
echo "Finish dump mongo: $BACKUP_FILE_PATH"
18+
19+
echo "Start s3 uploading..."
20+
21+
s3cmd put "$BACKUP_FILE_PATH" "$S3_PATH"
22+
23+
echo "Finish upload to S3: $S3_PATH"

0 commit comments

Comments
 (0)