Skip to content

Instantly share code, notes, and snippets.

@zvpunry
Last active January 25, 2023 15:02
Show Gist options
  • Save zvpunry/af667816d63df089cd34f81458598b6f to your computer and use it in GitHub Desktop.
Save zvpunry/af667816d63df089cd34f81458598b6f 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
# Original source: https://gist.github.com/wwerther/1306189
# Original documentation: http://web.archive.org/web/20190910001551/http://it.werther-web.de/2011/10/23/migrate-rsnapshot-based-backup-to-btrfs-snapshots
# Modified version: https://gist.github.com/zvpunry/af667816d63df089cd34f81458598b6f
#
# Arg 1: -rf
# Arg 2: /testbtrfs/backups/hourly.4/
# echo 1: $1 2: $@
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Try to delete the given path with btrfs subvolume delete first
# if this fails fall back to normal rm
if test "$1" = "-rf" -a -z "$3"
then
btrfs property set -ts "$2" ro false
btrfs subvolume delete -C "$2" > /dev/null || rm -rf "$2"
else
rm "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment