]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
filesystem-functions.pl: Add btrfs_create_snapshot() function
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 3 Jul 2025 15:04:08 +0000 (17:04 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 3 Jul 2025 15:04:08 +0000 (17:04 +0200)
This function can be used to very easily create a snapshot.

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

index f7a39ad6cb8c13eed424c39c145ce56950a36155..b6bc9ca69d2784d9784700fa0943a6c2311d674f 100644 (file)
@@ -615,6 +615,22 @@ sub btrfs_get_subvolumes ($) {
        return %subvolumes;
 }
 
+#
+## Easy to use function to create a new snapshot with a given name.
+#
+sub btrfs_create_snapshot ($) {
+       my ($name) = @_;
+
+       # Call btrfsctrl to create the new snapshot and pass the name.
+       my $ret = &General::system("$btrfsctrl", "snapshot-create", "$name");
+
+       # Return the return 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.
 ##