mirror of
https://github.com/napnap75/multiarch-docker-images.git
synced 2026-05-12 12:57:07 +02:00
Allow restic to be run from outside
This commit is contained in:
@@ -30,13 +30,9 @@ if [ -d /crontabs ] ; then
|
||||
for f in /crontabs/* ; do
|
||||
crontab -u $(basename $f) $f
|
||||
done
|
||||
else
|
||||
elif [[ "$BACKUP_CRONTAB" ]] ; then
|
||||
echo "# This crontab is generated by the entrypoint script, do not edit" > /tmp/crontab
|
||||
if [[ "$BACKUP_CRONTAB" ]] ; then
|
||||
echo -n "$BACKUP_CRONTAB" >> /tmp/crontab
|
||||
else
|
||||
echo -n "0 4 * * *" >> /tmp/crontab
|
||||
fi
|
||||
if [[ "$HC_PING_KEY" ]] ; then
|
||||
echo -n " runitor -slug ${HOSTNAME}-restic-backup --" >> /tmp/crontab
|
||||
fi
|
||||
|
||||
+20
-14
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Backup one directory
|
||||
# Backup one directory (from the mounted filesystem)
|
||||
function backup_dir {
|
||||
# Check if the dir to backup is mounted as a subdirectory of /root inside this container
|
||||
if [ "$1" = "" ]; then
|
||||
@@ -15,6 +15,7 @@ function backup_dir {
|
||||
fi
|
||||
}
|
||||
|
||||
# Backup one directory (from the local filesystem)
|
||||
function backup_local_dir {
|
||||
if [ "$1" = "" ]; then
|
||||
echo "[ERROR] Cannot backup the root directory. Have you correctly configured the volumes to backup for this container ?"
|
||||
@@ -46,11 +47,12 @@ if [ "$(restic --no-lock list locks -q)" != "" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
count_success=0
|
||||
count_failure=0
|
||||
if [ "$1" == "" ] || [ "$1" == "backup" ]; then
|
||||
count_success=0
|
||||
count_failure=0
|
||||
|
||||
# List all the containers
|
||||
for container_id in $(docker ps -aq) ; do
|
||||
# List all the containers
|
||||
for container_id in $(docker ps -aq) ; do
|
||||
container_json=$(docker inspect $container_id)
|
||||
# Get the name and namespace (in case of a container run in a swarm stack)
|
||||
container_name=$(echo $container_json | jq -r '.[].Name' | cut -d'/' -f2)
|
||||
@@ -137,19 +139,23 @@ for container_id in $(docker ps -aq) ; do
|
||||
docker exec $container_id bash -c "rm /tmp/database_backup.sql.gz"
|
||||
done
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# Send a notification to Slack
|
||||
if [[ "$SLACK_URL" != "" ]] ; then
|
||||
# Send a notification to Slack
|
||||
if [[ "$SLACK_URL" != "" ]] ; then
|
||||
curl -o /dev/null -s -m 10 --retry 5 -X POST --data-urlencode "payload={\"username\": \"rpi-docker-backup\", \"icon_emoji\": \":dvd:\", \"text\": \"Backup finished on host $HOSTNAME : $count_success succeeded, $count_failure failed\"}" $SLACK_URL
|
||||
fi
|
||||
fi
|
||||
|
||||
# Send a notification to Gotify
|
||||
if [[ "$GOTIFY_URL" != "" ]] ; then
|
||||
# Send a notification to Gotify
|
||||
if [[ "$GOTIFY_URL" != "" ]] ; then
|
||||
curl -o /dev/null -s -m 10 --retry 5 -X POST -H "accept: application/json" -H "Content-Type: application/json" -d "{\"priority\": 5, \"title\": \"Backup finished on host $HOSTNAME\", \"message\": \"Backup finished on host $HOSTNAME : $count_success succeeded, $count_failure failed\"}" $GOTIFY_URL
|
||||
fi
|
||||
fi
|
||||
|
||||
# Return a non zero exit code if an error happened
|
||||
if [ $count_failure -ne 0 ]; then
|
||||
# Return a non zero exit code if an error happened
|
||||
if [ $count_failure -ne 0 ]; then
|
||||
exit -1
|
||||
fi
|
||||
elif [ "$1" == "maintenance" ] ; then
|
||||
restic forget -q --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 2 --prune && restic prune -q
|
||||
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user