diff --git a/.gitignore b/.gitignore index aff804a..c913ac4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ !interactive.sh !mysql.sh !.dockerignore -!restore.sh \ No newline at end of file +!restore.sh +!entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 7770873..18c642f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,14 +4,14 @@ RUN apk add --no-cache mysql-client rclone bash fuse postgresql-client RUN mkdir /app && mkdir /config +COPY entrypoint.sh /app/entrypoint.sh COPY setup.sh /app/setup.sh COPY backup.sh /app/backup.sh COPY interactive.sh /app/interactive.sh COPY restore.sh /app/restore.sh -# COPY mysql.sh /app/mysql.sh WORKDIR /config VOLUME /config -ENTRYPOINT [ "/app/backup.sh" ] +ENTRYPOINT [ "/app/entrypoint.sh" ] diff --git a/README.md b/README.md index 7e83a62..8b5c9e4 100644 --- a/README.md +++ b/README.md @@ -61,5 +61,6 @@ docker run \ --network "dbNet" \ -v "/var/docker/backup:/config" \ $BACKUP_VOL \ - djeeberjr/backup + djeeberjr/backup \ + backup ``` diff --git a/backup.sh b/backup.sh index dd3e002..5930c1b 100755 --- a/backup.sh +++ b/backup.sh @@ -2,8 +2,6 @@ set -e -. /app/setup.sh - mkdir -p /backup/sqlDump for db in $(echo "$MYSQL_DUMP_DB" | sed 's/,/\n/g') diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..10e5e49 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env sh + +set -e + +COMMAND="$1" + +# print usage if no command is given +if [ -z "$COMMAND" ]; then + echo "Usage: $0 " + echo "Available commands:" + echo " backup" + echo " restore" + echo " init TODO" + echo " interactive" + exit 1 +fi + +. /app/setup.sh + +case "$COMMAND" in + backup) + # backup + /app/backup.sh + ;; + restore) + # restore + /app/restore.sh + ;; + init) + # init + # TODO: implement + /app/init.sh + ;; + interactive) + # interactive + /app/interactive.sh + ;; + *) + echo "Unknown command: $COMMAND" + exit 1 + ;; +esac diff --git a/interactive.sh b/interactive.sh index 2464679..76b694e 100755 --- a/interactive.sh +++ b/interactive.sh @@ -1,6 +1,4 @@ -#!/usr/bin/env bash - -. /app/setup.sh +#!/usr/bin/env bash mkdir -p /restore @@ -12,7 +10,7 @@ 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 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" diff --git a/restore.sh b/restore.sh index aa1d75b..1e2cd83 100644 --- a/restore.sh +++ b/restore.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash -. /app/setup.sh +VOLUMES=$(find /backup -maxdepth 1 -type d -printf '%f\n' | tail -n +2) + +#loop volumes +for VOLUME in $VOLUMES; do + echo "Restoring $VOLUME" + restic -v restore latest --include "/backup/$VOLUME" +done -# find . -maxdepth 1 -type d -printf '%f\n' | tail -n +2 -restic restore latest