a working version

This commit is contained in:
2025-08-25 20:30:58 +02:00
parent 5b1953df37
commit ffe05c9587

View File

@@ -3,11 +3,17 @@
set -eu -o pipefail
burpconf=/etc/burp/burp.conf
numFiles=10
numFiles=2
restoreFolder=/tmp/test_restauration
IFS=$(echo -ne '\b\n')
if [ $# -gt 0 ] ; then
cmdLine="-C $1"
fi
function _getRandomBurpFolders {
folderList=$(awk -F " = " '/^include/{ print $2}' $burpconf)
echo $folderList | sort --random-sort | tail -n 1
@@ -17,19 +23,41 @@ function _getRandomBackup {
burp -a l | awk '{ print $2}' | sort --random-sort | tail -n 1
}
function _cacheStale {
# 1 if given file older than 1 week
# 0 otherwhise
# file age in seconds = current_time - file_modification_time.
test -f $1 || return 2
fileage=$(($(date +%s) - $(stat -c '%Y' "$1")))
limit=$((7*24*3600))
diff=$((fileage-$limit ))
if [ $diff -lt 0 ] ; then return 0 ; else return 1 ; fi
}
function _getRandomFile {
f=$(_getRandomBurpFolders )
#f=/home/tom/Documents/Opendoor/Developpement/Scripts/Backups/BurpCheck/Test
test -d "${f}" || { echo "error opening $f" ; exit 1 ; }
find $f -type f | sort --random-sort | tail -n ${numFiles}
cacheFile=/tmp/burp_cache_$(echo $f | md5sum | cut -f1 -d ' ')
if ( $(_cacheStale "$cacheFile" )) ; then
readarray -d '' files < <(shuf -z $cacheFile)
else
readarray -d '' files < <(find $f -type f -print0 | shuf -z | tee $cacheFile)
fi
}
backup=$(_getRandomBackup)
files=$(_getRandomFile )
_getRandomFile
for file in $files ; do
echo "Trying to restore ${file} from backup #${backup}"
c=0
for file in "$files" ; do
let "c+=1"
echo "$file" | grep -q .git && break
echo "Trying to restore '${file}' from backup #${backup}"
burp -a r -b ${backup} -r "${file}" -d ${restoreFolder}
test $c -eq $numFiles || continue
done
exit $?