Menu

Support for MAX_KEEP_OLD_BACKUPS

Anonymous
2012-06-01
2013-05-02
  • Anonymous

    Anonymous - 2012-06-01

    Diff is below.

    rbme

    $ diff -ruN ./rbme-orig ./rbme
    --- ./rbme-orig 2010-07-14 19:00:51.000000000 +1000
    +++ ./rbme      2012-06-01 11:07:49.000000000 +1000
    @@ -62,6 +62,7 @@
     #
     # GSS  Schlomo Schapiro  <rbme@schlomo.schapiro.org>
     # FBU  Fridtjof Busse    <fbusse@probusiness.de>
    +# AA    Arya A.
     #
     # Versions:
     CHANGES='
    @@ -85,6 +86,7 @@
     2009-01-30 GSS changed %S to %s for SLES9 compatibility (thanks to werner.flamme@ufz.de)
     2009-08-31 GSS changed mail sending to sendmail in error routine
     2009-09-01 GSS fixed stupid bug where SENDMAIL was defined after the first use of die()
    +2012-06-01 AA   Added support for MAX_KEEP_OLD_BACKUPS, defaults to unlimited for backward compatibility
     '
     COPYRIGHT="Copyright (C) 2006,2009 Schlomo Schapiro"
    @@ -189,7 +191,10 @@
            die "ERROR: You must keep at least 1 old backup ('MIN_KEEP_OLD_BACKUPS' is '$MIN_KEEP_OLD_BACKUPS')"
     }
    -export BACKUP_PATH MIN_FREE_BEFORE_HOST_BACKUP MIN_INODES_BEFORE_HOST_BACKUP MIN_FREE_AFTER_HOST_BACKUP MIN_INODES_AFTER_HOST_BACKUP MIN_KEEP_OLD_BACKUPS RSYNC RSYNC_RSH RSYNC_EXTRA_OPTIONS VERBOSE REPORT STATISTICS DEBUG MAILTO MAILFROM MAILSTYLE LOGFILE
    +# How many old backups to keep at most (defaults to unlimited)
    +MAX_KEEP_OLD_BACKUPS="${MAX_KEEP_OLD_BACKUPS:=0}"
    +
    +export BACKUP_PATH MIN_FREE_BEFORE_HOST_BACKUP MIN_INODES_BEFORE_HOST_BACKUP MIN_FREE_AFTER_HOST_BACKUP MIN_INODES_AFTER_HOST_BACKUP MIN_KEEP_OLD_BACKUPS MAX_KEEP_OLD_BACKUPS RSYNC RSYNC_RSH RSYNC_EXTRA_OPTIONS VERBOSE REPORT STATISTICS DEBUG MAILTO MAILFROM MAILSTYLE LOGFILE
     # how do we call the situation, when the FS does not need free inodes (reiserfs ...) ?
     PLENTY=plenty
    @@ -229,7 +234,7 @@
     Current configuration:
     (change settings in /etc/rbme.conf (Master) and /etc/$ME.conf (Instance))
     EOF
    -       for var in BACKUP_PATH MIN_FREE_BEFORE_HOST_BACKUP MIN_INODES_BEFORE_HOST_BACKUP MIN_FREE_AFTER_HOST_BACKUP MIN_INODES_AFTER_HOST_BACKUP MIN_KEEP_OLD_BACKUPS RSYNC RSYNC_RSH RSYNC_EXTRA_OPTIONS VERBOSE REPORT STATISTICS DEBUG MAILTO MAILFROM MAILSTYLE LOGFILE; do
    +       for var in BACKUP_PATH MIN_FREE_BEFORE_HOST_BACKUP MIN_INODES_BEFORE_HOST_BACKUP MIN_FREE_AFTER_HOST_BACKUP MIN_INODES_AFTER_HOST_BACKUP MIN_KEEP_OLD_BACKUPS MAX_KEEP_OLD_BACKUPS RSYNC RSYNC_RSH RSYNC_EXTRA_OPTIONS VERBOSE REPORT STATISTICS DEBUG MAILTO MAILFROM MAILSTYLE LOGFILE; do
                    printf "\t%30s = %s\n" $var "${!var}"
            done
    @@ -315,8 +320,12 @@
                    lastbackup="$BACKUP_PATH/$client/$today"
                    backups=""
            fi
    -
    -       if test $space -lt $min_space -o $inodes -lt $min_inodes ; then
    +
    +       # Added support for MAX_KEEP_OLD_BACKUPS
    +       if test $space -lt $min_space -o $inodes -lt $min_inodes \
    +               || \
    +               test $MAX_KEEP_OLD_BACKUPS -gt 0 -a ${#backups[@]} -gt $MAX_KEEP_OLD_BACKUPS
    +       then
                    echo -e "\tRemoving old backups to free some disk space" 1>&2
                    numbackups=${#backups[*]}
                    echo -e "\tOldest backup (from $numbackups): $(basename "$backups")" 1>&2
    @@ -328,7 +337,9 @@
                    # accidentially with the next backup to delete :-)
                    while test $((numbackups-deleted)) -gt $MIN_KEEP_OLD_BACKUPS \
                            && \
    -                       test $space -lt $min_space -o $inodes -lt $min_inodes
    +                       test $space -lt $min_space -o $inodes -lt $min_inodes \
    +                       || \
    +                       test $MAX_KEEP_OLD_BACKUPS -gt 0 -a $((numbackups-deleted)) -gt $MAX_KEEP_OLD_BACKUPS
                    do
                            echo -en "\tHaving $space MB" 1>&2
                            test $min_inodes -gt 0 && echo -n " & $inodes inodes" 1>&2
    

    rbme.conf

    $ diff -ruN ./rbme.conf-orig ./rbme.conf
    --- ./rbme.conf-orig    2010-07-14 19:00:51.000000000 +1000
    +++ ./rbme.conf 2012-06-01 10:58:39.000000000 +1000
    @@ -30,6 +30,10 @@
     # This must be >1 !!
     MIN_KEEP_OLD_BACKUPS=5
    +# Keep at most this many backups, regardless of how much free
    +# space is present. Set to 0 (or unset) for unlimited.
    +MAX_KEEP_OLD_BACKUPS=0
    +
     # verbose mode, unset to suppress output
     VERBOSE=${VERBOSE=}
    
     
  • Anonymous

    Anonymous - 2012-06-01

    Sorry, my bad. The gt's should be ge's.

    Change:

    test $MAX_KEEP_OLD_BACKUPS -gt 0 -a ${#backups[@]} -gt $MAX_KEEP_OLD_BACKUPS
    

    to this:

    test $MAX_KEEP_OLD_BACKUPS -gt 0 -a ${#backups[@]} -ge $MAX_KEEP_OLD_BACKUPS
    

    and this:

     test $MAX_KEEP_OLD_BACKUPS -gt 0 -a $((numbackups-deleted)) -gt $MAX_KEEP_OLD_BACKUPS
    

    to this:

    test $MAX_KEEP_OLD_BACKUPS -gt 0 -a $((numbackups-deleted)) -ge $MAX_KEEP_OLD_BACKUPS
    

    Cheers

     

Log in to post a comment.