#!/bin/sh -e PROG="${0##*/}" Fatal() { echo "${0##*/}: $*" >&2 exit 1 } export LC_ALL=C sisyphus=/path/to/Sisyphus pattern='^/path/to/archive/Sisyphus/[[:digit:]]{4}/[[:digit:]]{2}/[[:digit:]]{2}$' format='/path/to/archive/Sisyphus/%CY/%Cm/%Cd\n/path/to/archive/Sisyphus/%TY/%Tm/%Td\n' old="$(find /path/to/archive/Sisyphus/ -type d -mindepth 3 -maxdepth 3 |egrep "$pattern" |sort -r |head -1)" || Fatal "old sisyphus lookup failed." [ -n "$old" -a -d "$old" ] || Fatal "old sisyphus lookup failed." new="$(find "$sisyphus"/i?86/base -mindepth 1 -maxdepth 1 -type f -name pkglist.\* -printf "$format")" || Fatal "new sisyphus lookup failed." new="$(echo "$new" |egrep "$pattern" |sort -r |head -1)" [ -n "$new" ] || Fatal "new sisyphus lookup failed." if [ "$old" = "$new" ]; then echo "$old: latest snapshot already exists." exit 0 fi if [ -d "$new" ]; then echo "$old: NON-latest snapshot already exists." exit 0 fi echo "New snapshot to be created: $new" mkdir -pv ${new%/*} cp -al "$old" "$new" rsync -va --delete-after --stats "$sisyphus"/ "$new"/