Skip to content

Instantly share code, notes, and snippets.

@gnanet
Created February 13, 2015 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnanet/46a7ccc0f3f2450e8599 to your computer and use it in GitHub Desktop.
Save gnanet/46a7ccc0f3f2450e8599 to your computer and use it in GitHub Desktop.
rdiff-backup mirror_metadata object removal sed calculator
#!/bin/bash
if [ $1 ]
then
object=$1
objectbase=`basename $1`
else
echo "$0 object"
echo " only full path of object in metadata works, object may be dir or file"
echo " dir object is recursive"
echo " example:"
echo " web/img/hd/800x600"
echo " works if metadata line contains"
echo " File web/img/hd/800x600"
exit
fi
# in second arg only specify uncompressed(!) filename of mirror_metadata
if [ $2 ]
then
if [ -f "$2" ]
then
mirror_metadata=$2
fi
else
# or hard code uncompressed(!) filename of mirror_metadata
mirror_metadata=mirror_metadata.2015-02-13T00:00:02+01:00.snapshot
fi
if [ -f "${mirror_metadata}" ]
then
if [ ! -f "${objectbase}_lines.txt" ]
then
grep -A10 -n "File ${object}" ${mirror_metadata} > ${objectbase}_lines.txt
fi
# get first line number to delete
firstline=`head -n1 ${objectbase}_lines.txt | grep File | awk -F':' {' print $1 '}`
# get last line number to delete
lastline=`tail -n2 ${objectbase}_lines.txt | grep -v "File " | awk -F'-' {' print $1 '}`
# print suggested sed command to delete all lines that refer to object
echo "sed -e \"${firstline},${lastline}d\" ${mirror_metadata}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment