From 727026bb76dc2e9cbc4d935db5eb03049d65385e Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Fri, 22 Apr 2016 13:52:29 -0400 Subject: functions to send btrfs diffs back to the parent (incomplete) these hard-code paths on my local machine the names of the generated files are also not useful --- btrfs-receive-root.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 btrfs-receive-root.sh (limited to 'btrfs-receive-root.sh') diff --git a/btrfs-receive-root.sh b/btrfs-receive-root.sh new file mode 100644 index 0000000..178fd64 --- /dev/null +++ b/btrfs-receive-root.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +layer_dir=/home/d/sami +seed_file=debian-live-8.4.0-amd64-standard.btrfs +layer_file=debian-live-8.4.0-amd64-standard.layer.$$.btrfs +layer_size=1000 +mountpoint=layer_dest.$$ + +disable_stdout() { exec 3>&1; exec >&2; } +enable_stdout() { exec >&3; } + +with_stdout() { enable_stdout; "$@"; disable_stdout; } + +create_layer_filesystem() +{ + [ ! -e "$layer_file" ] || return + mkdir -p "$mountpoint" && + dd if=/dev/zero of="$layer_file" bs=1M count="$layer_size" && + mount -o subvol=/,compress "$seed_file" "$mountpoint" && + layer_dev=$(losetup -f --show "$layer_file") && + btrfs device add "$layer_dev" "$mountpoint" && + mount -o rw,remount "$mountpoint" +} + +finish() +{ + umount "$mountpoint" && + btrfstune -S1 "$layer_file" +} + +set -ex + +cd "$layer_dir" && +disable_stdout && +create_layer_filesystem && +with_stdout btrfs receive "$mountpoint" && +finish -- cgit v1.2.3