made changes
This commit is contained in:
parent
7ab36da450
commit
ea1ab537c0
7
.gitignore
vendored
7
.gitignore
vendored
@ -2,7 +2,10 @@
|
||||
!.gitignore
|
||||
!Dockerfile
|
||||
!docker-compose.yml
|
||||
!entrypoint.sh
|
||||
!backup.sh
|
||||
!README.md
|
||||
!.drone.yml
|
||||
!init.sh
|
||||
!init.sh
|
||||
!setup.sh
|
||||
!interactive.sh
|
||||
!mysql.sh
|
12
Dockerfile
12
Dockerfile
@ -1,14 +1,16 @@
|
||||
FROM alpine:latest
|
||||
FROM restic/restic
|
||||
|
||||
RUN apk add --no-cache mysql-client restic rclone
|
||||
RUN apk add --no-cache mysql-client rclone bash fuse
|
||||
|
||||
RUN mkdir /app && mkdir /config
|
||||
|
||||
COPY entrypoint.sh /app/entrypoint.sh
|
||||
COPY init.sh /app/init.sh
|
||||
COPY setup.sh /app/setup.sh
|
||||
COPY backup.sh /app/backup.sh
|
||||
COPY interactive.sh /app/interactive.sh
|
||||
COPY mysql.sh /app/mysql.sh
|
||||
|
||||
WORKDIR /config
|
||||
|
||||
VOLUME /config
|
||||
|
||||
ENTRYPOINT /app/entrypoint.sh
|
||||
ENTRYPOINT /app/backup.sh
|
||||
|
15
backup.sh
Executable file
15
backup.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -e
|
||||
|
||||
. /app/setup.sh
|
||||
|
||||
mkdir -p /backup/sqlDump
|
||||
|
||||
for db in $(echo "$MYSQL_DUMP_DB" | sed 's/,/\n/g')
|
||||
do
|
||||
echo "Dumping db: $db"
|
||||
mysqldump --compact -P 3306 --host "$MYSQL_HOST" -u "$MYSQL_USERNAME" "-p$MYSQL_PASSWORD_ACTUAL" "$db" > "/backup/sqlDump/$db.sql"
|
||||
done
|
||||
|
||||
restic --verbose backup "/backup"
|
@ -3,15 +3,4 @@ version: "3"
|
||||
services:
|
||||
backup:
|
||||
build: .
|
||||
# entrypoint: /app/init.sh
|
||||
environment:
|
||||
- RCLONE_REMOTE=gdrive:/backupTest
|
||||
- RCLONE_CONFIG=/config/rclone.conf
|
||||
- ENC_PASSWORD=repopw
|
||||
- MYSQL_USERNAME=dbuser
|
||||
- MYSQL_PASSWORD=dbPassword
|
||||
- MYSQL_DUMP_DB=dbName1,dbName2
|
||||
- MYSQL_HOST=mariadb
|
||||
volumes:
|
||||
- ./mounts:/backup
|
||||
- ./config:/config
|
||||
image: djeeberjr/backup
|
@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -e
|
||||
|
||||
[ -z "${RCLONE_REMOTE}" ] && echo "\$RCLONE_REMOTE is not set" && exit 1
|
||||
[ -z "${RCLONE_CONFIG}" ] && echo "\$RCLONE_CONFIG is not set" && exit 1
|
||||
|
||||
if [ -n "${ENC_PASSWORD}" ]; then
|
||||
RESTIC_PASSWORD="${ENC_PASSWORD}"
|
||||
elif [ -n "${ENC_PASSWORD_FILE}" ]; then
|
||||
RESTIC_PASSWORD=$(cat "$ENC_PASSWORD_FILE")
|
||||
else
|
||||
echo "\$ENC_PASSWORD or \$ENC_PASSWORD_FILE is not set" && exit 1
|
||||
fi
|
||||
|
||||
if [ -n "${MYSQL_PASSWORD}" ]; then
|
||||
MYSQL_PASSWORD_ACTUAL="${MYSQL_PASSWORD}"
|
||||
elif [ -n "${MYSQL_PASSWORD_FILE}" ]; then
|
||||
MYSQL_PASSWORD_ACTUAL=$(cat "$MYSQL_PASSWORD_FILE")
|
||||
fi
|
||||
|
||||
mkdir -p /backup/sqlDump
|
||||
|
||||
for db in $(echo "$MYSQL_DUMP_DB" | sed 's/,/\n/g')
|
||||
do
|
||||
echo "Dumping db: $db"
|
||||
mysqldump --compact -P 3306 --host "$MYSQL_HOST" -u "$MYSQL_USERNAME" "-p$MYSQL_PASSWORD_ACTUAL" "$db" > "/backup/sqlDump/$db.sql"
|
||||
done
|
||||
|
||||
export RESTIC_PASSWORD
|
||||
|
||||
restic -r "rclone:$RCLONE_REMOTE" --verbose backup "/backup"
|
22
init.sh
22
init.sh
@ -1,22 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -e
|
||||
|
||||
[ -z "${RCLONE_REMOTE}" ] && echo "\$RCLONE_REMOTE is not set" && exit 1
|
||||
[ -z "${RCLONE_CONFIG}" ] && echo "\$RCLONE_CONFIG is not set" && exit 1
|
||||
|
||||
if [ -n "${ENC_PASSWORD}" ]; then
|
||||
RESTIC_PASSWORD="${ENC_PASSWORD}"
|
||||
elif [ -n "${ENC_PASSWORD_FILE}" ]; then
|
||||
RESTIC_PASSWORD=$(cat "$ENC_PASSWORD_FILE")
|
||||
else
|
||||
echo "\$ENC_PASSWORD or \$ENC_PASSWORD_FILE is not set" && exit 1
|
||||
fi
|
||||
|
||||
echo "Init new repo"
|
||||
|
||||
export RESTIC_PASSWORD
|
||||
|
||||
restic -r "rclone:$RCLONE_REMOTE" init
|
||||
|
||||
echo "Created new repo at $RCLONE_REMOTE"
|
22
interactive.sh
Executable file
22
interactive.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
. /app/setup.sh
|
||||
|
||||
mkdir -p /restore
|
||||
|
||||
echo "### Interactive mode ###"
|
||||
|
||||
echo "Remote: $RESTIC_REPOSITORY"
|
||||
echo "Volumes mounted at /backup"
|
||||
echo "########################"
|
||||
echo "rclone config # edit/add remote"
|
||||
echo "restic init # create new repo"
|
||||
echo "restic snapshots # list backups"
|
||||
echo "restic -restore latest --target /restore # restore latest backup to /restore"
|
||||
echo "restic dump latest /backup/sqlDump/dbname.sql # Dump sql dump to console"
|
||||
echo "/app/backup.sh # Create backup"
|
||||
echo "/app/mysql.sh # Open mysql client"
|
||||
echo "########################"
|
||||
|
||||
export PS1="[${RCLONE_REMOTE} \w]\$ "
|
||||
bash -i
|
33
setup.sh
Executable file
33
setup.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "${RCLONE_CONFIG}" ]; then
|
||||
RCLONE_CONFIG="/config/rclone.conf"
|
||||
[ -e "${RCLONE_CONFIG}" ] || echo "No config file found"
|
||||
echo "\$RCLONE_CONFIG not set. Defaulting to \"/config/rclone.conf\""
|
||||
fi
|
||||
|
||||
export RCLONE_CONFIG
|
||||
|
||||
if [ -z "$RCLONE_REMOTE" ]; then
|
||||
RCLONE_REMOTE="$(rclone listremotes | head -1)/backup"
|
||||
echo "\$RCLONE_REMOTE not set. Defaulting to \"$RCLONE_REMOTE\""
|
||||
fi
|
||||
|
||||
RESTIC_REPOSITORY="rclone:$RCLONE_REMOTE"
|
||||
|
||||
if [ -n "${RESTIC_PASSWORD}" ] && [ -n "$RESTIC_PASSWORD_FILE" ]; then
|
||||
echo "\$RESTIC_PASSWORD or \$RESTIC_PASSWORD_FILE is not set"
|
||||
fi
|
||||
|
||||
if [ -n "${MYSQL_PASSWORD}" ]; then
|
||||
MYSQL_PASSWORD_ACTUAL="${MYSQL_PASSWORD}"
|
||||
elif [ -n "${MYSQL_PASSWORD_FILE}" ]; then
|
||||
MYSQL_PASSWORD_ACTUAL=$(cat "$MYSQL_PASSWORD_FILE")
|
||||
fi
|
||||
|
||||
export RCLONE_REMOTE
|
||||
export RESTIC_PASSWORD
|
||||
export MYSQL_PASSWORD_ACTUAL
|
||||
export RESTIC_REPOSITORY
|
Loading…
Reference in New Issue
Block a user