Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
csuvajit committed May 18, 2024
0 parents commit 7e39c08
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/backup-tool.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: backup-tool

on:
workflow_dispatch:

jobs:
build:
name: backup-tool
runs-on: buildjet-4vcpu-ubuntu-2204-arm
strategy:
matrix:
collection: [PlayerLinks, ClanStores]

steps:
- name: Init Backup Tool
run: docker compose up
env:
MONGO_COLLECTION_NAME: ${{ matrix.collection }}
S3_BUCKET: ${{ secrets.S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
MONGO_HOST: ${{ secrets.MONGO_HOST }}
MONGO_PORT: ${{ secrets.MONGO_PORT }}
MONGO_USERNAME: ${{ secrets.MONGO_USERNAME }}
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
MONGO_DB_NAME: ${{ secrets.MONGO_DB_NAME }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
backup/
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM mongo:latest

RUN apt-get update && \
apt-get install -y python3-pip && \
pip3 install awscli && \
apt-get clean

COPY backup.sh /usr/local/bin/backup.sh

RUN chmod +x /usr/local/bin/backup.sh

ENTRYPOINT ["/usr/local/bin/backup.sh"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# backup-tool
23 changes: 23 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e

DATE=$(date +%Y-%m-%d-%H-%M-%S)
BACKUP_DIR="backup"

echo "Starting mongodump..."

mongodump --host $MONGO_HOST \
--port $MONGO_PORT \
--username $MONGO_USERNAME \
--password $MONGO_PASSWORD \
--authenticationDatabase admin \
--db $MONGO_DB_NAME \
--collection $MONGO_COLLECTION_NAME \
--out ./$BACKUP_DIR

tar -czf "$BACKUP_DIR-$DATE.tar.gz" -c "$BACKUP_DIR"

echo "Uploading backup to S3..."
aws s3 cp "./$BACKUP_DIR-$DATE.tar.gz" "s3://$S3_BUCKET/$MONGO_COLLECTION_NAME-$DATE.tar.gz"

echo "Backup and upload completed successfully."
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.8'

services:
backup-tool:
build: .
environment:
- S3_BUCKET=${S3_BUCKET}
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
- MONGO_HOST=${MONGO_HOST}
- MONGO_PORT=${MONGO_PORT}
- MONGO_USERNAME=${MONGO_USERNAME}
- MONGO_PASSWORD=${MONGO_PASSWORD}
- MONGO_DB_NAME=${MONGO_DB_NAME}
- MONGO_COLLECTION_NAME=${MONGO_COLLECTION_NAME}
volumes:
- ./backup.sh:/usr/local/bin/backup.sh
- ./backup:/backup

0 comments on commit 7e39c08

Please sign in to comment.