#!/bin/bash # $HeadURL: https://svn.pasta.freemyip.com/main/miniade/trunk/bin/nop-sh $ $LastChangedRevision: 10133 $ # Modules . $(miniade) || { echo "${0##*/}: ERROR: miniade failed (hint: run 'miniade' to see error)" >&2; exit 1; } # Configurable stuff CLEAN_UP_ROOT=/srv/vtape005 RDIFF_BACKUP_BACKED_UP_DLES=( $(sqlite3 -batch /var/lib/rdw2/rdw2.sqlite "select dle_id from dles where backup_method_id like 'rdiff%' order by dle_id;") ) # Other globals main() { local MY_ARGS # Defaults for options # Process options miniade_process_options MY_ARGS "$@" && set -- "${MY_ARGS[@]}" # Process arguments [ $# = 0 ] || usage # Sanity checks and derivations # Guts I=0 for RDIFF_BACKUP_BACKED_UP_DLE in "${RDIFF_BACKUP_BACKED_UP_DLES[@]}"; do miniade_debug 10 "main: $RDIFF_BACKUP_BACKED_UP_DLE ..." ((++I)) RDIFF_BACKUP_VERSION_HACK_NEEDED=true if $RDIFF_BACKUP_VERSION_HACK_NEEDED; then RDIFF_BACKUP_BACKED_UP_DLE_HOST_CMPNT=${RDIFF_BACKUP_BACKED_UP_DLE%%-*} RDIFF_BACKUP_VERSION=$(sed -nr "s/^[ ]*$RDIFF_BACKUP_BACKED_UP_DLE_HOST_CMPNT\).*=([^ ]+) *;;/\\1/p" /home/alexis/dev/def/rdw2/doc/examples/etc/rdw2/methods/Linux/Linux/backups/rdiff-backup) RDIFF_BACKUP_CMD="/root/.cache/rdiff-backup-wrapper/$RDIFF_BACKUP_VERSION/bin/rdiff-backup" else RDIFF_BACKUP_CMD=rdiff-backup fi DIRS=( $(find $CLEAN_UP_ROOT -maxdepth 3 -name $RDIFF_BACKUP_BACKED_UP_DLE) ) if [ ${#DIRS[*]} != 1 ]; then miniade_warning "$RDIFF_BACKUP_BACKED_UP_DLE: ${#DIRS[*]}: that's not precisely one matching directory (DIRS=${DIRS[*]})" continue fi DIR=${DIRS[0]} REVERSE_ORDERED_BACKUPS=( $($RDIFF_BACKUP_CMD -l --parsable-output $DIR 2>&1 | sed -nr 's/^([0-9]{10}) directory$/\1/p' | tac) ) if [ ${#REVERSE_ORDERED_BACKUPS[*]} = 0 ]; then miniade_warning "$RDIFF_BACKUP_BACKED_UP_DLE: there are no snapshots! is this is empty directory? (hint: RDIFF_BACKUP_CMD=$RDIFF_BACKUP_CMD, DIRS=${DIRS[*]})" continue elif [ ${#REVERSE_ORDERED_BACKUPS[*]} = 1 ]; then miniade_warning "$RDIFF_BACKUP_BACKED_UP_DLE: there is only one snapshot! (hint: this is not a problem for this script, but you might want to think about changing the backup schedule for this DLE or perhaps turning the host on?)" continue fi MOST_RECENT_BACKUP=${REVERSE_ORDERED_BACKUPS[0]} miniade_info "$RDIFF_BACKUP_BACKED_UP_DLE ($I/${#RDIFF_BACKUP_BACKED_UP_DLES[*]}): cleaning ..." miniade_evaler "$RDIFF_BACKUP_CMD --remove-older-than $MOST_RECENT_BACKUP --force $DIR" done } main "$@"