.
This commit is contained in:
11
docker/sqlclient/Dockerfile
Normal file
11
docker/sqlclient/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM duplicati/duplicati
|
||||
RUN apt update && apt install -y default-mysql-client && rm -rf /var/lib/apt/lists/*
|
||||
# Add metadata identifying these images as our build containers (this will be useful later!)
|
||||
|
||||
# clone repository
|
||||
|
||||
|
||||
RUN mkdir duplicati-sqlclient/scripts
|
||||
COPY /docker/sqlclient/scripts/* /duplicati-sqlclient/scripts/
|
||||
|
||||
EXPOSE 8200
|
||||
50
docker/sqlclient/scripts/backupdb.sh
Normal file
50
docker/sqlclient/scripts/backupdb.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
# mysql database backup.
|
||||
# executed by duplicati run-script-before-required
|
||||
# required environment variables:
|
||||
# DESTINATION
|
||||
# DB_HOST
|
||||
# DB_USER
|
||||
# DB_PASSWORD
|
||||
# DB_NAME
|
||||
# download directly from git
|
||||
# curl https://git.limbosolutions.com/kb/duplicati/raw/branch/main/docker/scripts/backupdb.sh > backupdb.sh | chmod +x backupdb.sh
|
||||
|
||||
#any error must stop execution
|
||||
set -e
|
||||
|
||||
if [ $DUPLICATI__OPERATIONNAME != "Backup" ]
|
||||
then
|
||||
echo "Not a backup operation. exiting!"
|
||||
#OK, run operation
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
||||
if [ -z ${DESTINATION} ]
|
||||
then
|
||||
echo "\$DESTINATION cannot be empty empty"
|
||||
#5: Error don't run operation
|
||||
exit 5
|
||||
fi
|
||||
|
||||
TARGETFILENAME=${DB_NAME}_dump_$(date -d "today" +"%Y%m%d%H%M%S").sql
|
||||
echo "dump file name:$TARGETFILENAME"
|
||||
|
||||
if [ -f /tmp/${TARGETFILENAME} ]
|
||||
then
|
||||
rm /tmp/${TARGETFILENAME}
|
||||
fi
|
||||
|
||||
|
||||
mysqldump -h ${DB_HOST} --user=${DB_USER} -p"${DB_PASSWORD}" ${DB_NAME} > /tmp/${TARGETFILENAME}
|
||||
|
||||
|
||||
if [ x$(find "$DB_BACKUP_TARGETFOLDER" -prune -empty) = x"$DB_BACKUP_TARGETFOLDER" ]; then
|
||||
echo "folder is empty... ignoring clean db dump folder"
|
||||
else
|
||||
rm -r ${DB_BACKUP_TARGETFOLDER} /*
|
||||
fi
|
||||
|
||||
mv /tmp/${TARGETFILENAME} ${DB_BACKUP_TARGETFOLDER}/${TARGETFILENAME}
|
||||
return 0
|
||||
Reference in New Issue
Block a user