-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup
executable file
·39 lines (32 loc) · 1.12 KB
/
cleanup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
DIR="$(dirname "$0")"
source $DIR/bin/load-env
backup_retention_last="$BACKUP_RETENTION_LAST"
backup_retention_daily="$BACKUP_RETENTION_DAILY"
backup_retention_weekly="$BACKUP_RETENTION_WEEKLY"
backup_retention_monthly="$BACKUP_RETENTION_MONTHLY"
backup_retention_yearly="$BACKUP_RETENTION_YEARLY"
backup_keep_within="$BACKUP_KEEP_WITHIN"
# Prune old backups
forget_flags=(
"--keep-last" "$backup_retention_last"
"--keep-daily" "$backup_retention_daily"
"--keep-weekly" "$backup_retention_weekly"
"--keep-monthly" "$backup_retention_monthly"
"--keep-yearly" "$backup_retention_yearly"
)
# Add keep-within flag if BACKUP_KEEP_WITHIN is set
if [ -n "$backup_keep_within" ]; then
forget_flags+=("--keep-within" "$backup_keep_within")
fi
# Add prune flag if BACKUP_PRUNE is not "false"
if [ "$BACKUP_PRUNE" != "false" ]; then
forget_flags+=("--prune")
fi
# Run the restic forget command with or without prune based on BACKUP_PRUNE
$DIR/restic forget "${forget_flags[@]}" "$@"
if [ $? -eq 0 ]; then
echo "Backup retention policy applied."
else
echo "Failed to apply backup retention policy."
fi