This commit is contained in:
2022-10-09 12:15:14 +01:00
parent 81c284fc18
commit adaf0ff85a
3 changed files with 75 additions and 12 deletions

View File

@@ -1,2 +1,46 @@
# duplicati
## Scripts
### Environment Variables
_Source: https://github.com/duplicati/duplicati/blob/master/Duplicati/Library/Modules/Builtin/run-script-example.sh_
- DUPLICATI__EVENTNAME
Eventname is BEFORE if invoked as --run-script-before, and AFTER if invoked as --run-script-after. This value cannot be changed by writing it back!
- DUPLICATI__OPERATIONNAME
Operation name can be any of the operations that Duplicati supports. For example it can be "Backup", "Cleanup", "Restore", or "DeleteAllButN". This value cannot be changed by writing it back!
- DUPLICATI__RESULTFILE
If invoked as --run-script-after this will contain the name of the file where result data is placed. This value cannot be changed by writing it back!
- DUPLICATI__REMOTEURL
This is the remote url for the target backend. This value can be changed by echoing --remoteurl = "new value".
- DUPLICATI__LOCALPATH
This is the path to the folders being backed up or restored. This variable is empty operations other than backup or restore. The local path can contain : to separate multiple folders. This value can be changed by echoing --localpath = "new value".
- DUPLICATI__PARSED_RESULT
This is a value indicating how well the operation was performed. It can take the values: Unknown, Success, Warning, Error, Fatal.
### Exit Codes
_Source: https://github.com/duplicati/duplicati/blob/master/Duplicati/Library/Modules/Builtin/run-script-example.sh_
The following exit codes are supported:
- 0: OK, run operation
- 1: OK, don't run operation
- 2: Warning, run operation
- 3: Warning, don't run operation
- 4: Error, run operation
- 5: Error don't run operation
- other: Error don't run operation

View File

@@ -1,25 +1,35 @@
#!/bin/bash
# Script example for creating a dump
# mysql database backup.
# executed by duplicati run-script-before-required
# required environment variables:
# DB_BACKUP_TARGETFOLDER
# DESTINATION
# DB_HOST
# DB_USER
# DB_PASSWORD
# DB_NAME
# Duplicati UI configure as a pre script
# donwload from git
# 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 [ -z ${DB_BACKUP_TARGETFOLDER} ]
if [ $DUPLICATI__OPERATIONNAME != "Backup" ]
then
echo "\$DB_BACKUP_TARGETFOLDER cannot be empty empty"
exit -1
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_dump_$(date -d "today" +"%Y%m%d%H%M%S").sql
TARGETFILENAME=${DB_NAME}_dump_$(date -d "today" +"%Y%m%d%H%M%S").sql
echo "dump file name:$TARGETFILENAME"
if [ -f /tmp/${TARGETFILENAME} ]
then
@@ -31,9 +41,10 @@ mysqldump -h ${DB_HOST} --user=${DB_USER} -p"${DB_PASSWORD}" ${DB_NAME} > /tmp/$
if [ x$(find "$DB_BACKUP_TARGETFOLDER" -prune -empty) = x"$DB_BACKUP_TARGETFOLDER" ]; then
echo "folder is empty... ignoring clean db dump folder"
echo "folder is empty... ignoring clean db dump folder"
else
rm -r ${DB_BACKUP_TARGETFOLDER}/*
rm -r ${DB_BACKUP_TARGETFOLDER} /*
fi
mv /tmp/${TARGETFILENAME} ${DB_BACKUP_TARGETFOLDER}/${TARGETFILENAME}
mv /tmp/${TARGETFILENAME} ${DB_BACKUP_TARGETFOLDER}/${TARGETFILENAME}
return 0

View File

@@ -1,3 +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/scripts/* /duplicati-sqlclient/scripts/
EXPOSE 8200