1
0
mirror of https://github.com/xzeldon/vwdump.git synced 2025-06-28 03:08:14 +03:00

Remove old backups (#11)

- Added `delete` script 🎉.
  - `DELETE_AFTER` variable must be greater than `0`.
This commit is contained in:
jmqm 2021-07-13 22:04:46 -05:00 committed by GitHub
parent 438a72650c
commit fcda17fc09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

10
delete.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/sh
# Go to the backups directory.
cd /backups
# Delete tar.xz archives older than x days.
find . -iname "*.tar.xz" -type f -mtime +$DELETE_AFTER -exec rm -f {} \;
# Echo that script ran.
echo "Deleted files older than $DELETE_AFTER days."

View File

@ -1,9 +1,10 @@
#!/bin/sh
BACKUP_CMD="/sbin/su-exec ${UID}:${GID} /app/backup.sh"
DELETE_CMD="/sbin/su-exec ${UID}:${GID} /app/delete.sh"
LOGS_FILE="/app/log/backup.log"
# Run backup script once ($1 = First argument passed).
# If passed "manual", run backup script once ($1 = First argument passed).
if [ "$1" = "manual" ]; then
echo "[INFO] Running one-time, started at $(date +"%F %r")."
$BACKUP_CMD
@ -12,8 +13,14 @@ fi
# Create cron jobs.
if [ "$(id -u)" -eq 0 ] && [ "$(grep -c "$BACKUP_CMD" "$CRONFILE")" -eq 0 ]; then
# Add backup script to cron job list.
echo "$CRON_TIME $BACKUP_CMD >> $LOGS_FILE 2>&1" | crontab -
# Delete after x days job here.
# Check if $DELETE_AFTER is not null and is greater than 0.
# If so, add it to the cron job list.
if [ -n "$DELETE_AFTER" ] && [[ "$DELETE_AFTER" -gt 0 ]]; then
echo "$CRON_TIME $DELETE_CMD >> $LOGS_FILE 2>&1" | crontab -
fi
fi
# Start crond if it's not running.