This commit is contained in:
2022-10-09 12:18:15 +01:00
parent adaf0ff85a
commit 396373af38
2 changed files with 1 additions and 1 deletions

View File

@@ -1,50 +0,0 @@
#!/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