diff options
| -rw-r--r-- | publish-snapshots.sh | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/publish-snapshots.sh b/publish-snapshots.sh index 8a73742..fe9e225 100644 --- a/publish-snapshots.sh +++ b/publish-snapshots.sh | |||
| @@ -21,6 +21,39 @@ LOCKFILE=$HOME/publish_lock | |||
| 21 | exec 200>$LOCKFILE | 21 | exec 200>$LOCKFILE |
| 22 | flock -n 200 || exit 1 | 22 | flock -n 200 || exit 1 |
| 23 | 23 | ||
| 24 | # Age out old snapshots under $SNAPSHOTSDIR/$subdir. The retention | ||
| 25 | # period depends on the project (the first path component of the | ||
| 26 | # subdir): gcc snapshots are huge, so keep them for a much shorter | ||
| 27 | # time than the other projects. Dated snapshot directories are named | ||
| 28 | # YYYY-MM-DD_HH-MM_EPOCH, so we use the embedded epoch to decide age | ||
| 29 | # rather than filesystem mtime (which is unreliable here because the | ||
| 30 | # parent directories get touched). The 'latest' symlink is skipped. | ||
| 31 | age_snapshots() { | ||
| 32 | local subdir="$1" | ||
| 33 | local project="${subdir%%/*}" | ||
| 34 | local days=365 | ||
| 35 | case "$project" in | ||
| 36 | gcc) days=30 ;; | ||
| 37 | esac | ||
| 38 | local now=$(date +%s) | ||
| 39 | local cutoff=$(( now - days*24*60*60 )) | ||
| 40 | local d name epoch | ||
| 41 | for d in "$SNAPSHOTSDIR/$subdir"/*; do | ||
| 42 | # Only consider real dated snapshot directories; skip the | ||
| 43 | # 'latest' symlink and any other non-directory entries. | ||
| 44 | [ -d "$d" ] && [ ! -L "$d" ] || continue | ||
| 45 | name=$(basename "$d") | ||
| 46 | epoch=${name##*_} | ||
| 47 | case "$epoch" in | ||
| 48 | ''|*[!0-9]*) continue ;; | ||
| 49 | esac | ||
| 50 | if [ "$epoch" -lt "$cutoff" ]; then | ||
| 51 | echo "Removing old snapshot $d (older than ${days} days)" | ||
| 52 | rm -rf "$d" | ||
| 53 | fi | ||
| 54 | done | ||
| 55 | } | ||
| 56 | |||
| 24 | if [ -f $PUBLISHDIR/$PUBLISHFILE ]; then | 57 | if [ -f $PUBLISHDIR/$PUBLISHFILE ]; then |
| 25 | # Make sure publishing dir is clean | 58 | # Make sure publishing dir is clean |
| 26 | rm -rf $PUBLISHINGDIR | 59 | rm -rf $PUBLISHINGDIR |
| @@ -48,6 +81,9 @@ if [ -f $PUBLISHDIR/$PUBLISHFILE ]; then | |||
| 48 | pdirs=$PUBLISHSUBDIR | 81 | pdirs=$PUBLISHSUBDIR |
| 49 | cd $SNAPSHOTSDIR | 82 | cd $SNAPSHOTSDIR |
| 50 | while [ $pdirs != "." ]; do touch $pdirs; pdirs=$(dirname $pdirs); done | 83 | while [ $pdirs != "." ]; do touch $pdirs; pdirs=$(dirname $pdirs); done |
| 84 | |||
| 85 | # Age out snapshots older than the retention period for this project | ||
| 86 | age_snapshots "$PUBLISHSUBDIR" | ||
| 51 | else | 87 | else |
| 52 | echo BAD subdir | 88 | echo BAD subdir |
| 53 | fi | 89 | fi |
