add readonly flag to folder snapshot

add new function snapshot_send to send a snapshot to another mounted partition or drive
master
David Kebler 2024-04-20 16:43:25 -07:00
parent 49913cf714
commit 7f5e3877cb
1 changed files with 35 additions and 2 deletions

View File

@ -101,17 +101,50 @@ find_subvolumes() {
} }
folder_snapshot() { folder_snapshot() {
if [[ $1 == "-r" ]];then
readonly=-r
shift 1
else
readonly=""
fi
for sv in $(find_subvolumes $1 1); do for sv in $(find_subvolumes $1 1); do
if [[ -d $2/$sv ]]; then if [[ -d $2/$sv ]]; then
echo snapshot $sv already exists in $2. You must manually delete target snapshots! echo snapshot $sv already exists in $2. You must manually delete target snapshots!
else else
sudo $BTRFS_BIN sub snap $1/$sv $2 sudo $BTRFS_BIN sub snap $readonly $1/$sv $2
fi fi
done done
} }
snapshot_send() {
if [[ $1 == "-e" ]];then
dr=""
shift 1
else
echo "snapshot_send <-e> <souce snapshot path> <destination folder on different partition> <destination extension>"
echo preface with -e to execute
dr="echo"
fi
temp="$(dirname $1)/tmp_send"
name=$(basename $1)
name=$(echo $name | cut -f 1 -d '.')
ext="$(echo $name | cut -s -f 2 -d '.')"
[[ $ext ]] && ext=".$ext"
[[ $3 ]] && ext=".$3"
sudo mkdir $temp
$dr sudo $BTRFS_BIN sub snap -r $1 $temp/$name$ext
if [[ $dr ]]; then
$dr "sudo $BTRFS_BIN send $temp/$name$ext | btrfs receive $2"
else
sudo $BTRFS_BIN send $temp/$name$ext | btrfs receive $2
fi
$dr sudo $BTRFS_BIN sub del $temp/$name$ext
ls -la $2
sudo rm -r $temp
}
mount_subvolume () { mount_subvolume () {
# echo sudo mount $1 -o subvol=$2 $3 # echo sudo mount $1 -o subvol=$2 $3
if mountpoint $3 &> /dev/null; then if mountpoint $3 &> /dev/null; then