Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add NodeJS and script/dump.js for Database Dump, this for Full Datebase Backup use #91

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a883e52
Create entry.sh-old
emengweb Dec 12, 2024
04c50ab
Create package.json
emengweb Dec 12, 2024
0224f69
Update package.json
emengweb Dec 12, 2024
d53979d
Create dump.js
emengweb Dec 12, 2024
d2ed033
Update entry.sh
emengweb Dec 12, 2024
401dea8
Update Dockerfile
emengweb Dec 12, 2024
ab5b082
Update Dockerfile
emengweb Dec 12, 2024
ff84d0f
Update backup.sh
emengweb Dec 12, 2024
79f0e3e
Update Dockerfile
emengweb Dec 12, 2024
18d51d9
Update backup.sh
emengweb Dec 12, 2024
d4feddf
Update backup.sh
emengweb Dec 12, 2024
a021c0d
Update Dockerfile
emengweb Dec 12, 2024
bb61f59
Update dump.js
emengweb Dec 12, 2024
3e5b1c3
Update backup.sh
emengweb Dec 12, 2024
2b0f6c8
Update dump.js
emengweb Dec 12, 2024
f4fc9ec
Update Dockerfile
emengweb Dec 12, 2024
4ee53e5
Update backup.sh
emengweb Dec 12, 2024
09d3a6d
Update dump.js
emengweb Dec 12, 2024
c7ff78f
Update README.md
emengweb Dec 12, 2024
cde9fe7
Update README.md
emengweb Dec 12, 2024
8e18cb1
Update dump.js
emengweb Dec 12, 2024
b482639
Update package.json
emengweb Dec 12, 2024
d88dead
Update dump.js
emengweb Dec 12, 2024
1869359
Update dump.js
emengweb Dec 12, 2024
e33997d
Update dump.js
emengweb Dec 12, 2024
96326fc
Update dump.js
emengweb Dec 12, 2024
15bd939
Update dump.js
emengweb Dec 12, 2024
b6c6314
Update dump.js
emengweb Dec 12, 2024
ccc9e04
Update README.md
emengweb Dec 12, 2024
84c64c7
Update dump.js
emengweb Dec 12, 2024
8755711
Update dump.js
emengweb Dec 12, 2024
9806565
Update README.md
emengweb Dec 12, 2024
1cfc36b
Update dump.js
emengweb Dec 12, 2024
95651a7
Update README.md
emengweb Dec 12, 2024
5fcd25e
Update backup.sh
emengweb Dec 13, 2024
fbb04da
Update README.md
emengweb Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN unzip rclone-current-linux-amd64.zip && mv rclone-*-linux-amd64/rclone /bin/

FROM restic/restic:0.16.0

RUN apk add --update --no-cache curl mailx
RUN apk add --update --no-cache curl mailx nodejs npm

COPY --from=rclone /bin/rclone /bin/rclone

Expand Down Expand Up @@ -36,6 +36,16 @@ ENV OS_REGION_NAME=""
ENV OS_INTERFACE=""
ENV OS_IDENTITY_API_VERSION=3

ENV DATABASE_TYPE=""
ENV DATABASE_HOST=""
ENV DATABASE_PORT=""
ENV DATABASE_USER=""
ENV DATABASE_PASSWORD=""
ENV DATABASE_NAME=""
ENV DATABASE_BACKUP_TIME="0-23"

ENV TZ="Asia/Shanghai"

# openshift fix
RUN mkdir /.cache && \
chgrp -R 0 /.cache && \
Expand All @@ -54,5 +64,14 @@ COPY backup.sh /bin/backup
COPY check.sh /bin/check
COPY entry.sh /entry.sh

RUN mkdir /script && \
chgrp -R 0 /script && \
chmod -R g=u /script
COPY package.json /script/package.json
COPY dump.js /script/dump.js
RUN chmod u+x /script/*
RUN cd /script && \
npm install

ENTRYPOINT ["/entry.sh"]
CMD ["tail","-fn0","/var/log/cron.log"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ The container is set up by setting [environment variables](https://docs.docker.c
* `OS_REGION_NAME` - Optional. When using restic with OpenStack Swift container.
* `OS_INTERFACE` - Optional. When using restic with OpenStack Swift container.
* `OS_IDENTITY_API_VERSION` - Optional. When using restic with OpenStack Swift container.

NEW Env For Database Dump
* `DATABASE_TYPE` - Optional. Specify the database type (mongo/mongodb/mysql/pg/postgres/postgresql). Specifying this option will enable the database backup function.
* `DATABASE_BACKUP_TIME` - Optional. Database backup is automatically enabled within the specified time range (default 0-23)
* `DATABASE_HOST` - Optional. Database host address
* `DATABASE_PORT` - Optional. Database host port (if not specified, it will automatically follow the default port value of the database type)
* `DATABASE_NAME` - Optional. Database name, Supports specifying multiple database names separated by ','. If not specified all database tables (except system tables) are used by default. Database type **mysql** AND **postgresql** MUST set.
* `DATABASE_USER` - Optional. Database Username
* `DATABASE_PASSWORD` - Optional. Database password

## Volumes

Expand Down
37 changes: 37 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,50 @@ logLast() {
echo "$1" >> ${lastLogfile}
}

backupDatebase(){
echo ""
echo "### Start ${DATABASE_TYPE} Dump ###"
echo "Backup Datebase: ${DATABASE_TYPE}"
# 检查 dump 目录是否存在,如果存在则删除
if [ -d "/script/dump" ]; then
rm -rf /script/dump
fi
mkdir /script/dump
# 运行 dump 脚本
cd /script
npm run dump
# 检查 /script/dump 目录下是否为空,不为空则复制 dump 数据到
if [ "$(ls -A /script/dump)" ]; then
# 检查 /data/dump 目录存在,自动删除旧备份;如果不存在则创建 dump 目录
if [ -d "/data/dump" ]; then
rm -rf /data/dump/*
else
mkdir /data/dump
fi
# 复制最新的备份
cp -r /script/dump /data/
echo ""
echo "MongoDB Dump List:"
ls -l /data/dump
else
echo "./dump Folder Empty, ${DATABASE_TYPE} Dump Fail."
fi
echo "### End ${DATABASE_TYPE} Dump ###"
echo ""
}

if [ -f "/hooks/pre-backup.sh" ]; then
echo "Starting pre-backup script ..."
/hooks/pre-backup.sh
else
echo "Pre-backup script not found ..."
fi

# Dump Datebase
if [ -n "${DATABASE_TYPE}" ]; then
backupDatebase
fi

start=`date +%s`
rm -f ${lastLogfile} ${lastMailLogfile}
echo "Starting Backup at $(date +"%Y-%m-%d %H:%M:%S")"
Expand Down
Loading