Compare commits

...

5 Commits

Author SHA1 Message Date
1e3600e140 feat: Add timezone
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-17 09:35:27 +02:00
67440a7f1f feat: Add datetime on log
All checks were successful
continuous-integration/drone/push Build is passing
2023-07-16 10:50:30 +02:00
1f29978152 feat: Add multi arch
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-26 15:23:39 +02:00
b607230f64 feat: Add registry configuration
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-26 15:11:49 +02:00
a6071706c6 feat: Update repository name
Some checks failed
continuous-integration/drone/push Build is failing
2023-06-26 14:57:45 +02:00
3 changed files with 46 additions and 18 deletions

View File

@ -1,14 +1,37 @@
---
# drone encrypt ResiLien/docker-s3-volume-watch $REGISTRY_USERNAME
kind: secret
name: REGISTRY_USERNAME
data: nWD+Q9IZSvWw6aDlxBgjvaQqsyU9Muub4A9wJMIfZ8A18g==
---
# drone encrypt ResiLien/docker-s3-volume-watch $REGISTRY_PASSWORD
kind: secret
name: REGISTRY_PASSWORD
data: fshphgiLW3gyuwhKHgSe7m6Y/LXtse2VEYABvjWYCov8w85+CMa5hjkHSiO+dgRCMOC4+OE5ZlZjD/5hAURi6TsBTZw0h5fWsnEjMR6L
---
kind: pipeline
type: docker
name: amd
name: amd64
platform:
os: linux
arch: amd64
steps:
- name: docker
image: plugins/docker
image: thegeeklab/drone-docker-buildx
privileged: true
settings:
username: kevinbacon
password: pa55word
repo: foo/bar
registry: registry.weko.io
username:
from_secret: REGISTRY_USERNAME
password:
from_secret: REGISTRY_PASSWORD
repo: registry.weko.io/simonc/docker-s3-volume-watch
tags:
- latest
platforms:
- linux/arm64
- linux/amd64

View File

@ -1,7 +1,7 @@
FROM peakcom/s5cmd:v2.1.0
label maintainer="RésiLien <admin+docker@resilien.fr>"
RUN apk --no-cache add inotify-tools bash
RUN apk --no-cache add inotify-tools bash tzdata
ADD watch /watch
VOLUME /data

29
watch
View File

@ -4,6 +4,11 @@
DEBUG=${DEBUG:-"Unknown Error"}
function log {
now=`date +"%Y-%m-%d %T"`
echo "[${now}] $1"
}
function usage {
cat <<-EOF
Usage: $PROGNAME [OPTIONS] <local-path> <remote-path>
@ -16,7 +21,7 @@ EOF
}
function error_exit {
echo "${1:-"Unknown Error"}" 1>&2
log "${1:-"Unknown Error"}" 1>&2
exit 1
}
@ -51,49 +56,49 @@ function restore {
fi
fi
echo "restoring $REMOTE => $LOCAL"
log "restoring $REMOTE => $LOCAL"
if ! $S3_PROG sync "$REMOTE/*" "$LOCAL"; then
error_exit "restore failed"
fi
}
function backup {
echo "backup $LOCAL => $REMOTE"
log "backup $LOCAL => $REMOTE"
if ! $S3_PROG sync "$LOCAL" "$REMOTE" $S3_SYNC_FLAGS; then
echo "backup failed" 1>&2
log "backup failed" 1>&2
return 1
fi
}
function final_backup {
echo "backup $LOCAL => $REMOTE"
log "backup $LOCAL => $REMOTE"
while ! $S3_PROG sync "$LOCAL" "$REMOTE" $S3_SYNC_FLAGS; do
echo "backup failed, will retry" 1>&2
log "backup failed, will retry" 1>&2
sleep 1
done
exit 0
}
function idle {
echo "ready"
log "ready"
log "RESTORE_INTERVAL: ${RESTORE_INTERVAL}"
while true; do
restore
if [[ -v $RESTORE_INTERVAL ]]; then
if [[ -v RESTORE_INTERVAL ]]; then
backup
timeout ${RESTORE_INTERVAL} inotifywait -m -e modify -e move -e create -e delete --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f' $LOCAL | while read date time file; do echo echo "The file '$file' appeared in directory '$path' via '$action'"; backup; done
timeout ${RESTORE_INTERVAL} inotifywait -m -e modify -e move -e create -e delete --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f' $LOCAL | while read date time file; do log "The file '$file' appeared in directory '$path' via '$action'"; backup; done
else
log "Without restore interval"
inotifywait -m -e modify -e move -e create -e delete --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f' $LOCAL |
while read date time file
do
echo echo "The file '$file' appeared in directory '$path' via '$action'"
log "The file '$file' appeared in directory '$path' via '$action'"
backup
done
fi
done
}
restore
trap final_backup SIGHUP SIGINT SIGTERM
trap "backup; idle" USR1