feat: add basic backup rotation command

This commit is contained in:
wpetit 2020-10-22 10:43:46 +02:00
parent 5647f8f9eb
commit d7c5c11060

View File

@ -31,6 +31,36 @@ function backup {
run_container "backup-volumes" "-v $backup_dir:$CONTAINER_BACKUP_BASE_DIR"
}
function restore {
local backup_date=$1
if [ -z "$backup_date" ]; then
echo 1>&2 "Vous devez spécifier une date au format YYYYMMDD en premier argument."
exit 1
fi
local backup_dir=$(readlink -f "$BACKUP_BASE_DIR/$BACKUP_DIR_PREFIX$backup_date")
if [ ! -d "$backup_dir" ]; then
echo 1>&2 "Le dossier de sauvegarde '$backup_dir' n'existe pas."
exit 1
fi
run_container "restore-volumes" "-v $backup_dir:$CONTAINER_BACKUP_BASE_DIR"
}
function rotate {
local retention=${1:-1}
local backup_dirs=( $(find -maxdepth 1 -type d -name "$BACKUP_DIR_PREFIX*" -printf "%f\n" | sort -r) )
echo "Rotating backups (retention: $retention)"
echo "Found ${#backup_dirs[@]} backup(s)"
for d in ${backup_dirs[@]:$retention}; do
local abs_dir="$(readlink -f $d)"
echo "Deleting backup '$abs_dir'"
rm -rf "$abs_dir"
done
}
function run_container {
local docker_cmd="$1"
local additional_docker_args="$2"
@ -66,24 +96,6 @@ function restore-volumes {
done
}
function restore {
local backup_date=$1
if [ -z "$backup_date" ]; then
echo 1>&2 "Vous devez spécifier une date au format YYYYMMDD en premier argument."
exit 1
fi
local backup_dir=$(readlink -f "$BACKUP_BASE_DIR/$BACKUP_DIR_PREFIX$backup_date")
if [ ! -d "$backup_dir" ]; then
echo 1>&2 "Le dossier de sauvegarde '$backup_dir' n'existe pas."
exit 1
fi
run_container "restore-volumes" "-v $backup_dir:$CONTAINER_BACKUP_BASE_DIR"
}
function main {
local command=$1
local command_args=${@:2}