a working version
This commit is contained in:
38
burpcheck.sh
38
burpcheck.sh
@@ -3,11 +3,17 @@
|
|||||||
set -eu -o pipefail
|
set -eu -o pipefail
|
||||||
|
|
||||||
burpconf=/etc/burp/burp.conf
|
burpconf=/etc/burp/burp.conf
|
||||||
numFiles=10
|
numFiles=2
|
||||||
restoreFolder=/tmp/test_restauration
|
restoreFolder=/tmp/test_restauration
|
||||||
|
|
||||||
IFS=$(echo -ne '\b\n')
|
IFS=$(echo -ne '\b\n')
|
||||||
|
|
||||||
|
if [ $# -gt 0 ] ; then
|
||||||
|
cmdLine="-C $1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function _getRandomBurpFolders {
|
function _getRandomBurpFolders {
|
||||||
folderList=$(awk -F " = " '/^include/{ print $2}' $burpconf)
|
folderList=$(awk -F " = " '/^include/{ print $2}' $burpconf)
|
||||||
echo $folderList | sort --random-sort | tail -n 1
|
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
|
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 {
|
function _getRandomFile {
|
||||||
f=$(_getRandomBurpFolders )
|
f=$(_getRandomBurpFolders )
|
||||||
|
#f=/home/tom/Documents/Opendoor/Developpement/Scripts/Backups/BurpCheck/Test
|
||||||
test -d "${f}" || { echo "error opening $f" ; exit 1 ; }
|
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)
|
backup=$(_getRandomBackup)
|
||||||
|
|
||||||
files=$(_getRandomFile )
|
_getRandomFile
|
||||||
|
|
||||||
for file in $files ; do
|
c=0
|
||||||
echo "Trying to restore ${file} from backup #${backup}"
|
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}
|
burp -a r -b ${backup} -r "${file}" -d ${restoreFolder}
|
||||||
|
test $c -eq $numFiles || continue
|
||||||
done
|
done
|
||||||
|
|
||||||
exit $?
|
exit $?
|
||||||
Reference in New Issue
Block a user