Skip to content

Instantly share code, notes, and snippets.

@tobert
Created April 30, 2013 19:15
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tobert/5491155 to your computer and use it in GitHub Desktop.
Save tobert/5491155 to your computer and use it in GitHub Desktop.
This would work equally well with ZFS. It would "work" with LVM snapshots, but it'd be very, very slow unless you do something to accelerate the LVM CoW volume like putting it on an SSD / ramdisk. Unionfs and aufs should also be fine.
#!/bin/bash
# snapshot the previous volume before updating
# otherwise there will be a CoW for each child, which could get slow quickly
btrfs subvolume snapshot /btrfs/base/precise-amd64-2013-04-01 /btrfs/base/precise-amd64-2013-04-31
# differential copy --inplace avoids the tempfile/mv so large files can remain shared
rsync -avx --inplace --delete server.domain.com::precise-amd64 /btrfs/base/precise-amd64-2013-04-31
# now make a snapshot for an app
btrfs subvolume snapshot /btrfs/base/precise-amd64-2013-04-31 /btrfs/image/ID
# then pull the app's 'overlay', no --delete since it should just be the diff
rsync -avx --inplace server.domain.com::app-ID /btrfs/image/ID
# now create a container for the app to run in
btrfs subvolume snapshot /btrfs/image/ID /btrfs/app/ID-INSTANCE
# check out your new container
chroot /btrfs/app/ID-INSTANCE /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment