#800 Issue closed
: Purge backups¶
Labels: won't fix / can't fix / obsolete
peptoni opened issue at 2016-03-16 17:38:¶
Relax-and-Recover (rear) Issue Template¶
Please fill in the following items before submitting a new issue:
- rear version (/usr/sbin/rear -V): Relax-and-Recover 1.17.2 / Git
- OS version (cat /etc/rear/os.conf or lsb_release -a): Ubuntu 14.04.4 LTS
- rear configuration files (cat /etc/rear/site.conf or cat
/etc/rear/local.conf):
BACKUP=NETFS
OUTPUT=USB
BACKUP_PROG=rsync
BACKUP_URL=usb:///dev/disk/by-label/backupB - Brief description of the issue
Could not find this in the docs. Is there anyway to purge the backups on media, or to keep the latest n backups?. I'd like to do backups, but keep only the latest n backups. Thank you very much. - Work-around, if any
didacog commented at 2016-03-16 19:05:¶
Hello @peptoni,
Maybe you will give a try to DRLM (www.drlm.org) to manage your ReaR backups.
One of the features is multiple backups management. You just need to set HISTBKPMAX=<number_of_bkps> in /etc/drlm/local.conf and manage them with: drlm CLI
Hope this can help you! ;)
Didac
peptoni commented at 2016-03-17 11:21:¶
Thanks @didacog. Nice utility, but I'm on standalone server right now.
I've found this:
Number of rescue environments/backups to retain on USB¶
USB_RETAIN_BACKUP_NR=2
on /usr/share/rear/conf/default.conf but it's not working for me. Even if I add this lines to /etc/rear/local.conf it's not working... I'v done 5 backups, but not purging older ones.
Any idea? Thanks in advance.
gdha commented at 2016-03-18 14:51:¶
script output/USB/Linux-i386/30_create_extlinux.sh
seems to use the
variable USB_RETAIN_BACKUP_NR
. So, it does not work you say?
peptoni commented at 2016-03-18 16:23:¶
At least for me, is not working. I've done up to 5 backups onto my USB drive but all of them remain on disk. There is, apparently, no purge. Is there any more info I can give you? Thanks in advance.
peptoni commented at 2016-03-18 16:25:¶
There is one difference with a standard setup. My drive isn't labeled "REAR-000". Is labeled "backup", because I have a previous working rsnapshot setup around that. Other than this, it's a standard setup, as far as I can tell.
lrirwin commented at 2016-03-18 17:27:¶
I wrote this script and called it "prunerearbackup".
It checks the average sizes of the backups and multiplies by 3 (for good
measure) to see if any pruning is needed.
I set it up to run an hour or more prior to the backup process.
You'd have to modify it to match your rear folder names and the disk
device...
#!/bin/bash
date
echo "Pruning backup media."
# Mount disk
echo "Mounting /dev/sdb1 on /mnt"
mount /dev/sdb1 /mnt
while true
do
# Disk usage
TOT=`df -BK /dev/sdb1 | grep "/dev/sdb1" | sed -e 's/ * / /g' -e 's/^ //' | cut -f2 -d" " | sed -e 's/K//'`
USE=`df -BK /dev/sdb1 | grep "/dev/sdb1" | sed -e 's/ * / /g' -e 's/^ //' | cut -f3 -d" " | sed -e 's/K//'`
AVL=`df -BK /dev/sdb1 | grep "/dev/sdb1" | sed -e 's/ * / /g' -e 's/^ //' | cut -f4 -d" " | sed -e 's/K//'`
# Backups on disk
CNT=`ls /mnt/rear/ccasvr/ | wc -l`
# Average per backup
AVG=`expr ${USE} / ${CNT}`
# Required available space defined for this site
REQ=`expr ${AVG} \* 3`
# Check and get out if there's enough space
[ ${AVL} -ge ${REQ} ] && break
# Check and get out if there's only the minimum number of backup copies or less on the media
[ ${CNT} -le 2 ] && break
DEL=`ls /mnt/rear/ccasvr/ | head -n 1`
echo "Removing ${DEL}"
rm -r /mnt/rear/ccasvr/${DEL}
# /bin/echo -e "Press Enter to continue: \c"
# read ans gbg
done
# Unmount disk
echo "Unmounting /dev/sdb1 from /mnt"
umount /mnt
date
peptoni commented at 2016-03-18 17:36:¶
Nice script. Very elaborated.
I would go more for a simple line like:
find /path/to/files* -mtime +30 -exec rm {} \;
Yours is disk space available oriented and mine is just time oriented.
Anyway, I'd love to find out about the integrated variable in ReaR.
gdha commented at 2017-04-25 18:42:¶
It is not a task for ReaR to purge backups - as it is against DR
principles - purging should be under user control (as was provided above
via a special script).
OTOH thank you for the question - it is an interesting point we should
keep an eye on.
[Export of Github issue for rear/rear.]