Created
January 12, 2015 23:39
-
-
Save Chaos99/a093bf5c9c2d2a834512 to your computer and use it in GitHub Desktop.
searches for a file or folder in all btrfs snapshots and prompts to delete them all (not working atm)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LIST=() | |
BASEDIR=$1 | |
SEARCH=$2 | |
FIND=$(/usr/bin/find $BASEDIR -maxdepth 1 -mindepth 1 -type d) | |
BTRFS="/sbin/btrfs" | |
echo "Scanning timeline:" | |
for snapshot in $FIND ; do | |
# echo "$snapshot" | |
if [ -d "$snapshot""/snapshot"$SEARCH ] ; then | |
LIST+=("$snapshot"); | |
echo -n "|"; | |
elif [ -f "$snapshot""/snapshot"$SEARCH ]; then | |
LIST+=("$snapshot"); | |
echo -n "|"; | |
else | |
echo -n "."; | |
fi | |
done | |
echo ""; | |
if [ -z "$LIST" ] ; then | |
echo "no snapshots found." | |
echo "Exiting ..."; | |
exit 0 | |
else | |
echo "${#LIST[@]} snapshots with file found:" | |
echo "from ${LIST[0]} to ${LIST[-1]}" | |
fi | |
read -p "Are you sure you want to delete $SEARCH in all these snapshots? " -n 1 -r | |
if [[ ! $REPLY =~ ^[Yy]$ ]] | |
then | |
echo ""; | |
exit 1; | |
fi | |
echo "" | |
echo "Deleting with btrfs:" | |
for s in "${LIST[@]}" ; do | |
mount -t btrfs -o rw,subvol=$s/snapshot rw /dev/sda3 /mnt/tmp | |
if [ -d "$snapshot""/snapshot"$SEARCH ] ; then | |
rm -rf /mnt/tmp$SEARCH | |
elif [ -f "$snapshot""/snapshot"$SEARCH ]; then | |
rm /mnt/tmp$SEARCH | |
fi | |
umount /mnt/tmp | |
echo "" | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment