]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
filesystem-functions.pl: Add btrfs_restore_snapshot() function
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 3 Jul 2025 15:05:32 +0000 (17:05 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 3 Jul 2025 15:05:32 +0000 (17:05 +0200)
Easy to use function to restore a snapshot by it's ID

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

index 0a3b4c4846bcae87db6548f1ad6aac62717c7361..d9a5f56176d7e6923330a97c56a2aff167ca3ffa 100644 (file)
@@ -649,6 +649,24 @@ sub btrfs_remove_snapshot ($) {
        return;
 }
 
+#
+## Easy to use function to restore a snapshot by it's ID.
+##
+## Requires the numeric ID of the snapshot.
+#
+sub btrfs_restore_snapshot($) {
+       my ($id) = @_;
+
+       # Call the btrfsctrl binary to restore the requested snapshot.
+       my $ret = &General::system("$btrfsctrl", "snapshot-restore", "$id");
+
+       # 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.
 ##