# Location where the btrfs binary lives.
my $btrfs_bin = "/usr/bin/btrfs";
+# Directory where BTRFS snapshots will be stored.
+my $btrfs_snapshot_dir = "/.snapshots/";
+
#
## Function which returns a lot of details about the known devices
## as a hash of hashes.
return @output;
}
+#
+## Function which calls the subvolume snapshot feature of the btrfs tool to create a snapshot.
+##
+## Possible argument:
+## name: The name of the snapshot
+## source: If it is different than "/"
+## target: If it is different than the defined "$btrfs_snapshot_dir"
+#
+sub btrfs_subvolume_snapshot ($$$) {
+ my ($name, $source, $target) = @_;
+
+ # Default to "/" if no source has been given.
+ $source //= "/";
+
+ # Default to snapshot dir if no target has been specified.
+ $target //= "$btrfs_snapshot_dir";
+
+ # Generate destination path.
+ my $destination = "$target" . "$name";
+
+ # Call the btrfs binary to create the snapshot.
+ my $ret = &General::system("$btrfs_bin", "subvolume", "snapshot", "$source", "$destination");
+
+ # Return the error code if there was one.
+ return $ret if($ret);
+
+ # Return nothing on success.
+ return;
+}
+
1;