From 263ba5296d2d8ab0531a09fb6c70eba6bd426850 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Thu, 17 Oct 2024 11:24:08 -0700 Subject: [PATCH] add dir2subvol function to convert directory to subvolume fix - bug in copy function where collected arguments were erased. --- modules/filesystem/btrfs/btrfs.mod | 24 ++++++++++++++++++++ modules/utility/copy.lib | 35 ++++++++++++++++++------------ 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/modules/filesystem/btrfs/btrfs.mod b/modules/filesystem/btrfs/btrfs.mod index ae0f67d..1967679 100644 --- a/modules/filesystem/btrfs/btrfs.mod +++ b/modules/filesystem/btrfs/btrfs.mod @@ -250,7 +250,31 @@ alias btsub="sudo $BTRFS_BIN subvolume" +dir2subvol () { + # Directory to convert into BTRFS subvolume +dirPath="$1" + +getfacl -R "$dirPath" > /tmp/_perms + +# Rename original dierctory +sudo mv "${dirPath}" "${dirPath}_original" + +# Create btrfs subvolume +sudo $BTRFS_BIN subvolume create "${dirPath}" + +# Copy as "reflink" for speed and save space +sudo cp --archive --one-file-system --reflink=always \ + "${dirPath}_original/." "${dirPath}" + +# Remove old directory +sudo rm -rf --one-file-system "${dirPath}_original" + +setfacl --restore=/tmp/_perms + +rm -f /tmp/_perms + +} diff --git a/modules/utility/copy.lib b/modules/utility/copy.lib index 8f91a26..df25678 100644 --- a/modules/utility/copy.lib +++ b/modules/utility/copy.lib @@ -21,7 +21,7 @@ copy () { cat < source destination --- +rsync