mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-11-10 00:30:29 +01:00
make log output more consistent
This commit is contained in:
parent
17a3523ded
commit
204a0862c6
@ -28,7 +28,7 @@ AWS_SECRET_ACCESS_KEY="<xxx>"
|
|||||||
AWS_S3_BUCKET_NAME="<xxx>"
|
AWS_S3_BUCKET_NAME="<xxx>"
|
||||||
|
|
||||||
# This is the FQDN of your storage server, e.g. `storage.example.com`.
|
# This is the FQDN of your storage server, e.g. `storage.example.com`.
|
||||||
# You can leave it blank when working against AWS S3.
|
# Do not set this when working against AWS S3.
|
||||||
# AWS_ENDPOINT="<xxx>"
|
# AWS_ENDPOINT="<xxx>"
|
||||||
|
|
||||||
########### BACKUP PRUNING
|
########### BACKUP PRUNING
|
||||||
|
@ -12,7 +12,7 @@ function info {
|
|||||||
echo -e "\n[INFO] $1\n"
|
echo -e "\n[INFO] $1\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
info "Backup starting"
|
info "Preparing backup"
|
||||||
DOCKER_SOCK="/var/run/docker.sock"
|
DOCKER_SOCK="/var/run/docker.sock"
|
||||||
|
|
||||||
if [ -S "$DOCKER_SOCK" ]; then
|
if [ -S "$DOCKER_SOCK" ]; then
|
||||||
@ -25,12 +25,12 @@ if [ -S "$DOCKER_SOCK" ]; then
|
|||||||
CONTAINERS_TO_STOP_TOTAL="$(cat $TEMPFILE | wc -l)"
|
CONTAINERS_TO_STOP_TOTAL="$(cat $TEMPFILE | wc -l)"
|
||||||
CONTAINERS_TOTAL="$(docker ps --format "{{.ID}}" | wc -l)"
|
CONTAINERS_TOTAL="$(docker ps --format "{{.ID}}" | wc -l)"
|
||||||
rm "$TEMPFILE"
|
rm "$TEMPFILE"
|
||||||
echo "$CONTAINERS_TOTAL containers running on host in total"
|
echo "$CONTAINERS_TOTAL containers running on host in total."
|
||||||
echo "$CONTAINERS_TO_STOP_TOTAL containers marked to be stopped during backup"
|
echo "$CONTAINERS_TO_STOP_TOTAL containers marked to be stopped during backup."
|
||||||
else
|
else
|
||||||
CONTAINERS_TO_STOP_TOTAL="0"
|
CONTAINERS_TO_STOP_TOTAL="0"
|
||||||
CONTAINERS_TOTAL="0"
|
CONTAINERS_TOTAL="0"
|
||||||
echo "Cannot access \"$DOCKER_SOCK\", won't look for containers to stop"
|
echo "Cannot access \"$DOCKER_SOCK\", won't look for containers to stop."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$CONTAINERS_TO_STOP_TOTAL" != "0" ]; then
|
if [ "$CONTAINERS_TO_STOP_TOTAL" != "0" ]; then
|
||||||
@ -57,9 +57,9 @@ fi
|
|||||||
|
|
||||||
if [ ! -z "$AWS_S3_BUCKET_NAME" ]; then
|
if [ ! -z "$AWS_S3_BUCKET_NAME" ]; then
|
||||||
info "Uploading backup to remote storage"
|
info "Uploading backup to remote storage"
|
||||||
echo "Will upload to bucket \"$AWS_S3_BUCKET_NAME\""
|
echo "Will upload to bucket \"$AWS_S3_BUCKET_NAME\"."
|
||||||
mc cp "$BACKUP_FILENAME" "backup-target/$AWS_S3_BUCKET_NAME"
|
mc cp "$BACKUP_FILENAME" "backup-target/$AWS_S3_BUCKET_NAME"
|
||||||
echo "Upload finished"
|
echo "Upload finished."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$BACKUP_FILENAME" ]; then
|
if [ -f "$BACKUP_FILENAME" ]; then
|
||||||
@ -68,7 +68,7 @@ if [ -f "$BACKUP_FILENAME" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
info "Backup finished"
|
info "Backup finished"
|
||||||
echo "Will wait for next scheduled backup"
|
echo "Will wait for next scheduled backup."
|
||||||
|
|
||||||
if [ ! -z "$BACKUP_RETENTION_DAYS" ]; then
|
if [ ! -z "$BACKUP_RETENTION_DAYS" ]; then
|
||||||
info "Pruning old backups"
|
info "Pruning old backups"
|
||||||
@ -76,18 +76,19 @@ if [ ! -z "$BACKUP_RETENTION_DAYS" ]; then
|
|||||||
|
|
||||||
rule_applies_to=$(mc rm --fake --recursive -force --older-than "${BACKUP_RETENTION_DAYS}d" "backup-target/$bucket" | wc -l)
|
rule_applies_to=$(mc rm --fake --recursive -force --older-than "${BACKUP_RETENTION_DAYS}d" "backup-target/$bucket" | wc -l)
|
||||||
if [ "$rule_applies_to" == "0" ]; then
|
if [ "$rule_applies_to" == "0" ]; then
|
||||||
echo "No backups found that match the configured retention period. Doing nothing."
|
echo "No backups found older than the configured retention period of $BACKUP_RETENTION_DAYS days."
|
||||||
|
echo "Doing nothing."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
available=$(mc ls "backup-target/$bucket" | wc -l)
|
total=$(mc ls "backup-target/$bucket" | wc -l)
|
||||||
|
|
||||||
if [ "$rule_applies_to" == "$available" ]; then
|
if [ "$rule_applies_to" == "$total" ]; then
|
||||||
echo "Using a retention of $BACKUP_RETENTION_DAYS days would prune all currently existing backups, will not continue."
|
echo "Using a retention of ${BACKUP_RETENTION_DAYS} days would prune all currently existing backups, will not continue."
|
||||||
echo "If this is what you want, please remove files manually instead of using this script."
|
echo "If this is what you want, please remove files manually instead of using this script."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mc rm --recursive -force --older-than "${BACKUP_RETENTION_DAYS}d" "backup-target/$bucket"
|
mc rm --recursive -force --older-than "${BACKUP_RETENTION_DAYS}d" "backup-target/$bucket"
|
||||||
echo "Successfully pruned all backups older than ${BACKUP_RETENTION_DAYS} days"
|
echo "Successfully pruned ${rule_applies_to} backups older than ${BACKUP_RETENTION_DAYS} days."
|
||||||
fi
|
fi
|
||||||
|
@ -27,9 +27,9 @@ source env.sh
|
|||||||
mc alias set backup-target "https://$AWS_ENDPOINT" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY"
|
mc alias set backup-target "https://$AWS_ENDPOINT" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY"
|
||||||
|
|
||||||
# Add our cron entry, and direct stdout & stderr to Docker commands stdout
|
# Add our cron entry, and direct stdout & stderr to Docker commands stdout
|
||||||
echo "Installing cron.d entry with expression $BACKUP_CRON_EXPRESSION"
|
echo "Installing cron.d entry with expression $BACKUP_CRON_EXPRESSION."
|
||||||
echo "$BACKUP_CRON_EXPRESSION backup 2>&1" | crontab -
|
echo "$BACKUP_CRON_EXPRESSION backup 2>&1" | crontab -
|
||||||
|
|
||||||
# Let cron take the wheel
|
# Let cron take the wheel
|
||||||
echo "Starting cron in foreground"
|
echo "Starting cron in foreground."
|
||||||
crond -f -l 8
|
crond -f -l 8
|
||||||
|
Loading…
Reference in New Issue
Block a user