Compare commits
5 Commits
a4458133f3
...
19f857e1fd
| Author | SHA1 | Date | |
|---|---|---|---|
| 19f857e1fd | |||
| 9c5f9e8d30 | |||
| 734a6b99e0 | |||
| 1b8e7fde9b | |||
| f5c52389e6 |
116
README.md
116
README.md
@@ -1,56 +1,55 @@
|
|||||||
# Duplicati
|
# Duplicati
|
||||||
|
|
||||||
## Custom Docker Images
|
## Docker
|
||||||
|
|
||||||
### Duplicati with mySql Client
|
### Duplicati/mySql Client - image
|
||||||
|
|
||||||
|
Image contains all scripts
|
||||||
|
|
||||||
[+ Information](docker/mysqlclient/README.md)
|
[+ Information](docker/mysqlclient/README.md)
|
||||||
|
|
||||||
|
|
||||||
## Send Mail
|
|
||||||
|
|
||||||
```bash
|
|
||||||
#for testing
|
|
||||||
duplicati-cli send-mail --send-mail-password="pass" --send-mail-to="target@mail.lan" --send-mail-username="suer@mail.lan" --send-mail-url="smtp://serveraddress:25"
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Global Settings
|
|
||||||
|
|
||||||
```bash
|
|
||||||
|
|
||||||
--send-mail-any-operation=true
|
|
||||||
--send-mail-body=%RESULT%
|
|
||||||
--send-mail-level=all
|
|
||||||
--send-mail-subject=Duplicati %OPERATIONNAME% report for -> %backup-name%
|
|
||||||
--send-mail-to=destination@mail.lan
|
|
||||||
--send-http-result-output-format=Duplicati
|
|
||||||
--send-mail-url=smtp://serveraddress:25
|
|
||||||
--send-mail-password=password
|
|
||||||
--send-mail-username=user@mail.lan
|
|
||||||
|
|
||||||
```
|
|
||||||
## Scripts
|
## Scripts
|
||||||
|
|
||||||
### Transfer To another system
|
_Source: https://github.com/duplicati/duplicati/blob/master/Duplicati/Library/Modules/Builtin/run-script-example.sh_
|
||||||
1. Copy docker compose and execute on another system
|
|
||||||
2. Check volumes and service started succesfully
|
### Backup mySql Database
|
||||||
3. Stop all compose services
|
|
||||||
4. Change volume on duplicati service to user a temporary volume example (duclicati_tmpdata)
|
|
||||||
5. Check if all volumes are writable on duplication service
|
Using option run-script-before-required on duplicati job set value to [script](scripts/duplicati-mysql-backup).
|
||||||
6. Start only the duplicati service (with temporary volume) on target system
|
And job will create a database dump configured using environment variables.
|
||||||
7. On source system Stop app services on docker compose except duplicati
|
Example:
|
||||||
8. Execute a full backup ou source system
|
--run-script-after=/root/repos/duplicate/scripts/duplicati-mysql-backup
|
||||||
9. On target system execute a manual restore to original destination
|
|
||||||
10. Stop duplicati
|
[script](scripts/duplicati-mysql-backup)
|
||||||
11. Change duplicati to use original volume
|
|
||||||
12. And change volumes on duplicati to RO
|
```bash
|
||||||
13. Start all services
|
#/etc/default/duplicati-mysql
|
||||||
14. Check everything ok
|
MYSQL_HOST="mysqlserver"
|
||||||
|
MYSQL_USER="msqluser"
|
||||||
|
MYSQL_PASSWORD="msqlpassord"
|
||||||
|
MYSQL_DATABASE="msqlpassword"
|
||||||
|
MYSQL_BACKUP_FOLDER="/var/db-dumps"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Influxdb Reporting
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#/etc/default/duplicati-influxdb
|
||||||
|
INFLUXDB_SERVER=http://influxdb01.lan:8086
|
||||||
|
INFLUXDB_BUCKET=bucketname
|
||||||
|
INFLUXDB_ORG=orgname
|
||||||
|
INFLUXDB_TOKEN=influxdbname
|
||||||
|
```
|
||||||
|
|
||||||
|
Add [script](scripts/duplicati-influxdb-notify) to default settings.
|
||||||
|
Example:
|
||||||
|
--run-script-after=/root/repos/duplicate/scripts/duplicati-influxdb-notify
|
||||||
|
|
||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
|
|
||||||
_Source: https://github.com/duplicati/duplicati/blob/master/Duplicati/Library/Modules/Builtin/run-script-example.sh_
|
Source: https://github.com/duplicati/duplicati/blob/master/Duplicati/Library/Modules/Builtin/run-script-example.sh_
|
||||||
|
|
||||||
- DUPLICATI__EVENTNAME
|
- DUPLICATI__EVENTNAME
|
||||||
|
|
||||||
@@ -78,8 +77,7 @@ _Source: https://github.com/duplicati/duplicati/blob/master/Duplicati/Library/Mo
|
|||||||
|
|
||||||
### Exit Codes
|
### Exit Codes
|
||||||
|
|
||||||
_Source: https://github.com/duplicati/duplicati/blob/master/Duplicati/Library/Modules/Builtin/run-script-example.sh_
|
|
||||||
|
|
||||||
The following exit codes are supported:
|
The following exit codes are supported:
|
||||||
|
|
||||||
- 0: OK, run operation
|
- 0: OK, run operation
|
||||||
@@ -89,3 +87,35 @@ The following exit codes are supported:
|
|||||||
- 4: Error, run operation
|
- 4: Error, run operation
|
||||||
- 5: Error don't run operation
|
- 5: Error don't run operation
|
||||||
- other: Error don't run operation
|
- other: Error don't run operation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## cli
|
||||||
|
|
||||||
|
## Send Mail
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#for testing
|
||||||
|
duplicati-cli send-mail --send-mail-password="pass" --send-mail-to="target@mail.lan" --send-mail-username="suer@mail.lan" --send-mail-url="smtp://serveraddress:25"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
|
||||||
|
### Send Email
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
--send-mail-any-operation=true
|
||||||
|
--send-mail-body=%RESULT%
|
||||||
|
--send-mail-level=all
|
||||||
|
--send-mail-subject=Duplicati %OPERATIONNAME% report for -> %backup-name%
|
||||||
|
--send-mail-to=destination@mail.lan
|
||||||
|
--send-http-result-output-format=Duplicati
|
||||||
|
--send-mail-url=smtp://serveraddress:25
|
||||||
|
--send-mail-password=password
|
||||||
|
--send-mail-username=user@mail.lan
|
||||||
|
|
||||||
|
```
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#check ../README.md for more information
|
|
||||||
|
|
||||||
FROM duplicati/duplicati
|
FROM duplicati/duplicati
|
||||||
RUN apt update && apt install -y default-mysql-client && rm -rf /var/lib/apt/lists/*
|
RUN apt update && apt install -y default-mysql-client && rm -rf /var/lib/apt/lists/*
|
||||||
RUN mkdir duplicati-mysqlclient
|
|
||||||
RUN mkdir duplicati-mysqlclient/scripts
|
|
||||||
COPY /docker/mysqlclient/scripts/* /duplicati-mysqlclient/scripts/
|
COPY /scripts/* /usr/local/bin
|
||||||
RUN chmod +x /duplicati-mysqlclient/scripts/*
|
RUN chmod +x /usr/local/bin/duplicati-influxdb-notify
|
||||||
|
RUN chmod +x /usr/local/bin/duplicati-mysql-backup
|
||||||
|
|
||||||
EXPOSE 8200
|
EXPOSE 8200
|
||||||
@@ -1,28 +1,20 @@
|
|||||||
# Duplicati / mySql Client
|
# Duplicati / mySql Client
|
||||||
|
|
||||||
Using option run-script-before-required on duplicati job set value to /duplicati-mysqlclient/scripts/backupdb.sh.
|
|
||||||
And job will create a database dump configured using docker environment variables
|
|
||||||
|
|
||||||
## Build Image
|
|
||||||
|
|
||||||
### docker
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
||||||
#Executed on repository root folder
|
#Executed on repository root folder
|
||||||
docker build -t duplicati-mysqlclient:latest -f docker/mysqlclient/Dockerfile .
|
docker build -t duplicati-mysqlclient:latest -f docker/mysqlclient/Dockerfile .
|
||||||
|
|
||||||
```
|
```
|
||||||
### tar
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
||||||
#Executed on repository root folder
|
#Executed on repository root folder
|
||||||
sudo docker build -t duplicati-mysqlclient:latest -f docker/mysqlclient/Dockerfile --output type=tar,dest=build/duplicati-mysqlclient.tar .
|
sudo docker build -t duplicati-mysqlclient:latest -f docker/mysqlclient/Dockerfile --output type=tar,dest=build/duplicati-mysqlclient.tar .
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Portainer
|
## Portainer
|
||||||
|
|
||||||
Images -> Build a new Image -> URL
|
Images -> Build a new Image -> URL
|
||||||
|
|
||||||
@@ -33,9 +25,8 @@ Images -> Build a new Image -> URL
|
|||||||
**Dockerfile path:** docker/mysqlclient/Dockerfile
|
**Dockerfile path:** docker/mysqlclient/Dockerfile
|
||||||
|
|
||||||
|
|
||||||
## Run Container
|
|
||||||
|
|
||||||
### Docker Compose
|
## Docker Compose
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
version: "3"
|
version: "3"
|
||||||
@@ -47,7 +38,10 @@ services:
|
|||||||
- MYSQL_DATABASE=${MYSQL_DATABASE}
|
- MYSQL_DATABASE=${MYSQL_DATABASE}
|
||||||
- MYSQL_USER=${MYSQL_USER}
|
- MYSQL_USER=${MYSQL_USER}
|
||||||
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
|
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
|
||||||
- DESTINATION=/db-dumps
|
- INFLUXDB_SERVER=${INFLUXDB_SERVER}
|
||||||
|
- INFLUXDB_BUCKET=${INFLUXDB_BUCKET}
|
||||||
|
- INFLUXDB_ORG=${INFLUXDB_ORG}
|
||||||
|
- INFLUXDB_TOKEN=:{INFLUXDB_TOKEN}
|
||||||
volumes:
|
volumes:
|
||||||
- duplicati-data:/data
|
- duplicati-data:/data
|
||||||
- db-dumps:/db-dumps
|
- db-dumps:/db-dumps
|
||||||
@@ -57,4 +51,21 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
duplicati-data:
|
duplicati-data:
|
||||||
db-dumps:
|
db-dumps:
|
||||||
````
|
```
|
||||||
|
|
||||||
|
### Transfer To another system
|
||||||
|
1. Copy docker compose and execute on another system
|
||||||
|
2. Check volumes and service started succesfully
|
||||||
|
3. Stop all compose services
|
||||||
|
4. Change volume on duplicati service to user a temporary volume example (duclicati_tmpdata)
|
||||||
|
5. Check if all volumes are writable on duplication service
|
||||||
|
6. Start only the duplicati service (with temporary volume) on target system
|
||||||
|
7. On source system Stop app services on docker compose except duplicati
|
||||||
|
8. Execute a full backup ou source system
|
||||||
|
9. On target system execute a manual restore to original destination
|
||||||
|
10. Stop duplicati
|
||||||
|
11. Change duplicati to use original volume
|
||||||
|
12. And change volumes on duplicati to RO
|
||||||
|
13. Start all services
|
||||||
|
14. Check everything ok
|
||||||
|
|
||||||
|
|||||||
81
scripts/duplicati-influxdb-notify
Executable file
81
scripts/duplicati-influxdb-notify
Executable file
@@ -0,0 +1,81 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
if [ -f "/etc/default/duplicati-influxdb" ]; then
|
||||||
|
export $(cat /etc/default/duplicati-influxdb)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "~/.config/duplicati-influxdb" ]; then
|
||||||
|
export $(cat ~/default/duplicati-influxdb)
|
||||||
|
fi
|
||||||
|
|
||||||
|
TAGS=""
|
||||||
|
MESSAGE_FIELD_VALUE=""
|
||||||
|
|
||||||
|
|
||||||
|
UNSCAPED=""
|
||||||
|
ESCAPED=""
|
||||||
|
|
||||||
|
escape_tag_str () {
|
||||||
|
ESCAPED=${UNSCAPED//[ ]/\\ }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if [[ ! -z "$HOSTNAME" ]]; then
|
||||||
|
UNSCAPED=$HOSTNAME
|
||||||
|
escape_tag_str
|
||||||
|
TAGS="${TAGS},host=${ESCAPED}"
|
||||||
|
MESSAGE_FIELD_VALUE="${MESSAGE_FIELD_VALUE} ${HOSTNAME}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -z "$DUPLICATI__EVENTNAME" ]]; then
|
||||||
|
UNSCAPED=$DUPLICATI__EVENTNAME
|
||||||
|
escape_tag_str
|
||||||
|
TAGS="${TAGS},eventName=\"${ESCAPED}\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -z "$DUPLICATI__OPERATIONNAME" ]]; then
|
||||||
|
UNSCAPED=$DUPLICATI__OPERATIONNAME
|
||||||
|
escape_tag_str
|
||||||
|
TAGS="${TAGS},operationName=${ESCAPED}"
|
||||||
|
MESSAGE_FIELD_VALUE="${MESSAGE_FIELD_VALUE} ${DUPLICATI__OPERATIONNAME}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -z "$DUPLICATI__backup_name" ]]; then
|
||||||
|
UNSCAPED=$DUPLICATI__backup_name
|
||||||
|
escape_tag_str
|
||||||
|
TAGS="${TAGS},backupName=${ESCAPED}"
|
||||||
|
MESSAGE_FIELD_VALUE="${MESSAGE_FIELD_VALUE} ${DUPLICATI__backup_name}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -z "$DUPLICATI__PARSED_RESULT" ]]; then
|
||||||
|
UNSCAPED=$DUPLICATI__PARSED_RESULT
|
||||||
|
escape_tag_str
|
||||||
|
TAGS="${TAGS},status=${ESCAPED}"
|
||||||
|
MESSAGE_FIELD_VALUE="${MESSAGE_FIELD_VALUE} ${DUPLICATI__PARSED_RESULT}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -z "$DUPLICATI__RESULTFILE" ]]; then
|
||||||
|
UNSCAPED=$DUPLICATI__RESULTFILE
|
||||||
|
escape_tag_str
|
||||||
|
TAGS="${TAGS},resultFile=${ESCAPED}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -z "$DUPLICATI__LOCALPATH" ]]; then
|
||||||
|
UNSCAPED=$DUPLICATI__LOCALPATH
|
||||||
|
escape_tag_str
|
||||||
|
TAGS="${TAGS},localPath=${ESCAPED}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
FIELDS="message=\"Duplicati ${MESSAGE_FIELD_VALUE}\""
|
||||||
|
#echo $TAGS
|
||||||
|
|
||||||
|
curl --request POST \
|
||||||
|
"$INFLUXDB_SERVER/write?db=$INFLUXDB_BUCKET&ORG=$INFLUXDB_ORG" \
|
||||||
|
--header "Authorization: Token $INFLUXDB_TOKEN" \
|
||||||
|
--header "Content-Type: text/plain; charset=utf-8" \
|
||||||
|
--header "Accept: application/json" \
|
||||||
|
--data-raw "duplicati${TAGS} ${FIELDS}" > /dev/null 2>&1
|
||||||
|
|
||||||
|
exit 0
|
||||||
29
docker/mysqlclient/scripts/backupdb.sh → scripts/duplicati-mysql-backup
Normal file → Executable file
29
docker/mysqlclient/scripts/backupdb.sh → scripts/duplicati-mysql-backup
Normal file → Executable file
@@ -1,16 +1,27 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# mysql database backup.
|
# mysql database backup.
|
||||||
# executed by duplicati run-script-before-required
|
# executed by duplicati run-script-before-required
|
||||||
# required environment variables:
|
# required environment variables:
|
||||||
# DESTINATION
|
|
||||||
# MYSQL_HOST
|
# MYSQL_HOST
|
||||||
# MYSQL_USER
|
# MYSQL_USER
|
||||||
# MYSQL_PASSWORD
|
# MYSQL_PASSWORD
|
||||||
# MYSQL_DATABASE
|
# MYSQL_DATABASE
|
||||||
|
# MYSQL_BACKUP_FOLDER
|
||||||
|
|
||||||
#any error must stop execution
|
#any error must stop execution
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
if [ -f "/etc/default/duplicati-mysql" ]; then
|
||||||
|
export $(cat /etc/default/duplicati-mysql)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "~/.config/duplicati-mysql" ]; then
|
||||||
|
export $(cat ~/default/duplicati-mysql)
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ $DUPLICATI__OPERATIONNAME == "Backup" ]
|
if [ $DUPLICATI__OPERATIONNAME == "Backup" ]
|
||||||
then
|
then
|
||||||
echo "Backup Job!!"
|
echo "Backup Job!!"
|
||||||
@@ -20,12 +31,12 @@ else
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[-z "$MYSQL_BACKUP_FOLDER" ]]; then
|
||||||
|
MYSQL_BACKUP_FOLDER="/var/db-dumps"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z ${DESTINATION} ]
|
if [ ! -d $MYSQL_BACKUP_FOLDER ]; then
|
||||||
then
|
mkdir -p $MYSQL_BACKUP_FOLDER;
|
||||||
echo "\$DESTINATION environment variable cannot be empty empty"
|
|
||||||
#5: Error don't run operation
|
|
||||||
exit 5
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TARGETFILENAME=${MYSQL_DATABASE}_dump_$(date -d "today" +"%Y%m%d%H%M%S").sql
|
TARGETFILENAME=${MYSQL_DATABASE}_dump_$(date -d "today" +"%Y%m%d%H%M%S").sql
|
||||||
@@ -40,10 +51,10 @@ fi
|
|||||||
mysqldump -h ${MYSQL_HOST} --user=${MYSQL_USER} -p"${MYSQL_PASSWORD}" ${MYSQL_DATABASE} > /tmp/${TARGETFILENAME}
|
mysqldump -h ${MYSQL_HOST} --user=${MYSQL_USER} -p"${MYSQL_PASSWORD}" ${MYSQL_DATABASE} > /tmp/${TARGETFILENAME}
|
||||||
|
|
||||||
|
|
||||||
if [ x$(find "$DESTINATION" -prune -empty) = x"$DESTINATION" ]; then
|
if [ x$(find "$MYSQL_BACKUP_FOLDER" -prune -empty) = x"$MYSQL_BACKUP_FOLDER" ]; then
|
||||||
echo "folder is empty... ignoring clean db dump folder"
|
echo "folder is empty... ignoring clean db dump folder"
|
||||||
else
|
else
|
||||||
rm -r ${DESTINATION}/*
|
rm -r ${MYSQL_BACKUP_FOLDER}/*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mv /tmp/${TARGETFILENAME} ${DESTINATION}/${TARGETFILENAME}
|
mv /tmp/${TARGETFILENAME} ${MYSQL_BACKUP_FOLDER}/${TARGETFILENAME}
|
||||||
Reference in New Issue
Block a user