From e00a049ba7306b9ba238d095578ca92893114ebd Mon Sep 17 00:00:00 2001 From: jblu Date: Tue, 15 Aug 2023 21:35:05 -0500 Subject: [PATCH] Initial thoughts --- .dockerignore | 4 ++++ .gitignore | 0 Dockerfile | 4 ++++ entrypoint.sh | 7 ++++++ seafile-backup.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 entrypoint.sh create mode 100644 seafile-backup.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f9bcfc9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.gitignore +Dockerfile +LICENSE +*.md \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b602b75 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM alpine:latest +RUN apk add --no-cache mariadb-client rclone curl supercronic +COPY entrypoint.sh opt +CMD ["/opt/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..380b4a5 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +CRON_CONFIG_FILE="/opt/crontab" + +echo "${CRON} sh /opt/seafile-backup.sh" > $CRON_CONFIG_FILE + +exec supercronic -passthrough-logs -quiet $CRON_CONFIG_FILE \ No newline at end of file diff --git a/seafile-backup.sh b/seafile-backup.sh new file mode 100644 index 0000000..03f21aa --- /dev/null +++ b/seafile-backup.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# Variables +DATE=`date +%F` +TIME=`date +%H%M` +BACKUPDIR=/backup +SEAFDIR=/opt/seafile +BACKUPFILE=$BACKUPDIR/seafile-$DATE-$TIME.tar +TEMPDIR=/tmp/seafile-$DATE-$TIME + +# Shutdown seafile +docker exec $seafilecontainer $SEAFDIR/seafile-server-latest/seahub.sh stop +docker exec $seafilecontainer $SEAFDIR/seafile-server-latest/seafile.sh stop + +# Create directories +if [ ! -d $BACKUPDIR ] + then + echo Creating Backupdirectory $BACKUPDIR... + mkdir -pm 0600 $BACKUPDIR +fi +if [ ! -d $TEMPDIR ] + then + echo Create temporary directory $TEMPDIR... + mkdir -pm 0600 $TEMPDIR + mkdir -m 0600 $TEMPDIR/databases + mkdir -m 0600 $TEMPDIR/data +fi + +# Dump data / copy data +echo Dumping ccnet database... +mysqldump -h $mysqlhost -u $mysqlusername -p $mysqlpassword --skip-opt ccnet-db > $TEMPDIR/databases/ccnet-db.sql.`date +"%Y-%m-%d-%H-%M-%S"` +if [ -e $TEMPDIR/databases/ccnet-db.sql.* ]; then echo ok.; else echo ERROR.; fi +echo Dumping SeaFile database... +mysqldump -h $mysqlhost -u $mysqlusername -p $mysqlpassword --skip-opt seafile-db > $TEMPDIR/databases/seafile-db.sql.`date +"%Y-%m-%d-%H-%M-%S"` +if [ -e $TEMPDIR/databases/seafile-db.sql.* ]; then echo ok.; else echo ERROR.; fi +echo Dumping SeaHub database... +mysqldump -h $mysqlhost -u $mysqlusername -p $mysqlpassword --skip-opt seahub-db > $TEMPDIR/databases/seahub-db.sql.`date +"%Y-%m-%d-%H-%M-%S"` +if [ -e $TEMPDIR/databases/seahub-db.sql.* ]; then echo ok.; else echo ERROR.; fi + +echo Copying seafile directory... +rsync -az $SEAFDIR/* $TEMPDIR/data +if [ -d $TEMPDIR/data/seafile-data ]; then echo ok.; else echo ERROR.; fi + +# Start the server +docker exec $seafilecontainer $SEAFDIR/seafile-server-latest/seafile.sh start +docker exec $seafilecontainer $SEAFDIR/seafile-server-latest/seahub.sh start-fastcgi + +# compress data +echo Archive the backup... +cd $TEMPDIR +tar -cf $BACKUPFILE * +gzip $BACKUPFILE +if [ -e $BACKUPFILE.gz ]; then echo ok.; else echo ERROR.; fi + +# Cleanup +echo Deleting temporary files... +rm -Rf $TEMPDIR +if [ ! -d $TEMPDIR ]; then echo ok.; else echo ERROR.; fi \ No newline at end of file