Does anyone have a post-run script that will automatically zip up a given backup into a single file and delete the folder, leaving only the archive? I want each backup to be a single file. I searched the thread a bit and saw several people asking for this over the years, but I couldn't find an actual script to do it.
Also, will such a script interfere with the plugin's ability to clean up old backups? If so, how can I avoid this issue?
The end result I want is for 3 days of backups to be kept, with each backup being a single archive file.
I tried to ask ChatGPT to write one, but it completely failed to do so.
Alternatively, if someone could point me to documentation about scripts (e.g., I saw a post saying there is variable support to target backup directories directly, but did not see documentation listing variables, etc.) that would be helpful too.
EDIT
Looks like ChatGPT was able to pull it off after all! This is working for me. I'll include it here in case anyone else wants something like this. You'll need to change the log file directory to be wherever you want it, though, and change 3 days to whatever you want as well.
#!/bin/bash
# Accept input from plugin
ARCHIVE_FOLDER="$2"
# Log file
LOG_FILE="/mnt/user/Backups/post_backup_debug.log"
echo "[$(date)] ARCHIVE_FOLDER=$ARCHIVE_FOLDER" >> "$LOG_FILE"
# Safety check
if [ -z "$ARCHIVE_FOLDER" ]; then
echo "[$(date)] โ ARCHIVE_FOLDER not set" >> "$LOG_FILE"
exit 1
fi
# Zip destination
ZIP_DEST=$(dirname "$ARCHIVE_FOLDER")
BASE_NAME=$(basename "$ARCHIVE_FOLDER")
ZIP_PATH="$ZIP_DEST/${BASE_NAME}.zip"
# Create zip
zip -r "$ZIP_PATH" "$ARCHIVE_FOLDER"
# Delete original folder if zip succeeded
if [ $? -eq 0 ]; then
rm -rf "$ARCHIVE_FOLDER"
echo "[$(date)] โ
Zipped and deleted $ARCHIVE_FOLDER" >> "$LOG_FILE"
else
echo "[$(date)] โ Zip failed for $ARCHIVE_FOLDER" >> "$LOG_FILE"
exit 1
fi
# Retention: Only delete zips with Appdata format older than 3 days
find "$ZIP_DEST" -type f -name "ab_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9].zip" -mtime +3 \
-exec rm -f {} \; \
-exec echo "[$(date)] ๐งน Deleted matching zip: {}" >> "$LOG_FILE" \;
exit 0