]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
filesystem-functions.pl: Add btrfs_remove_snapshot() function
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 5 May 2024 15:01:12 +0000 (17:01 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 5 May 2024 15:01:12 +0000 (17:01 +0200)
Easy to use function to delete a snapshot by it's ID

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/filesystem-functions.pl

index 19a0978ae8acc7d654d87e529ca2e9a6ae64fa17..10c24df869affd63e1c24495f65e3b7d97e98e0f 100644 (file)
@@ -664,6 +664,28 @@ sub btrfs_create_snapshot ($) {
        return;
 }
 
+#
+## Easy to use function to delete a snapshot by it's ID.
+##
+## Requires the numeric ID of the snapshot.
+## Optional a volume can be specified if it differs from the default one.
+#
+sub btrfs_remove_snapshot ($$) {
+       my ($id, $volume) = @_;
+
+       # Assign default value if no volume has been given.
+       $volume //="/";
+
+       # Call the btrfs binary to delete the requested snapshot.
+       my $ret = &General::system("$btrfs_bin", "subvolume", "delete", "-c", "-i", "$id", "$volume");
+
+       # Return the error code if there was one.
+       return $ret if ($ret);
+
+       # Return nothing on success.
+       return;
+}
+
 #
 ## Private function to filter the output of btrfs_subvolume_list command.
 ##