Skip to content

Instantly share code, notes, and snippets.

@pommi
Created August 31, 2012 19:19
Show Gist options
  • Save pommi/3557761 to your computer and use it in GitHub Desktop.
Save pommi/3557761 to your computer and use it in GitHub Desktop.
a small shell script that can be used within rsnapshot as cmd_rm. It provides snapshots generated with btrfs instead of hard-links
#!/bin/sh
# Arg 1: -rf
# Arg 2: /testbtrfs/backups/hourly.4/
# echo 1: $1 2: $@
# Try to delete the given path with btrfs subvolume delete first
# Check if inode number == 256 (all subvolumes have inode number 256)
if [ "$1" = "-rf" -a "$3" = "" -a $(stat --printf='%i' $2) -eq 256 ]; then
# "trying to delete with btrfs"
btrfs subvolume delete $2
error=$?
# if this fails fall back to normal rm (this shoudn't be needed anymore because of the inode check)
if [ $error -eq 13 ]; then
# EC 13 => The directory specified is no subvolume
rm $@
elif [ $error -ne 0 ]; then
echo Error while deleting with btrfs $?
fi
else
rm $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment