Skip to content

Commit

Permalink
separate btrfs volumes from local volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
ccomb committed Mar 15, 2018
1 parent f37e9e8 commit 32d4bc3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ before_script:
- sudo mkdir /tmp/btrfs_mount_point
- sudo mount -o loop /var/lib/docker/btrfs.img /tmp/btrfs_mount_point/
- sudo btrfs subvolume create /tmp/btrfs_mount_point/snapshots
- sudo btrfs subvolume create /tmp/btrfs_mount_point/volumes
- sudo btrfs subvolume create /tmp/btrfs_mount_point/buttervolumes
- sudo btrfs subvolume create /tmp/btrfs_mount_point/received
- sudo umount /tmp/btrfs_mount_point/
- sudo rm -rf /tmp/btrfs_mount_point/
- sudo service docker stop
- sudo mkdir -p /var/lib/docker/volumes
- sudo mkdir -p /var/lib/docker/buttervolumes
- sudo mkdir -p /var/lib/docker/snapshots
- sudo mkdir -p /var/lib/docker/received
- sudo mount -o loop,subvol=volumes /var/lib/docker/btrfs.img /var/lib/docker/volumes
- sudo mount -o loop,subvol=volumes /var/lib/docker/btrfs.img /var/lib/docker/buttervolumes
- sudo mount -o loop,subvol=snapshots /var/lib/docker/btrfs.img /var/lib/docker/snapshots
- sudo mount -o loop,subvol=received /var/lib/docker/btrfs.img /var/lib/docker/received
- sudo service docker start
Expand Down
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
CHANGELOG
=========

1.5 (unreleased)
****************
-

- BREAKING : BTRFS volumes are now stored in a different directory

1.4 (2018-02-01)
****************

- Add clone command
- replace sync by `btrfs filesystem sync`


1.3.1 (2017-10-22)
******************

Expand Down
20 changes: 10 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ You can build a docker image with the provided Dockerfile::
Install and run
***************

Make sure the directory ``/var/lib/docker/volumes`` is living in a BTRFS
Make sure the directory ``/var/lib/docker/buttervolumes`` is living in a BTRFS
filesystem. It can be a BTRFS mountpoint or a BTRFS subvolume or both.
You should also create the directory for the unix socket of the plugin::

Expand All @@ -63,7 +63,7 @@ Either from the image you just built::

Or directly by pulling a `prebaked image <https://hub.docker.com/r/anybox/buttervolume/>`_ from the Docker hub::

$ docker run --privileged -v /var/lib/docker/volumes:/var/lib/docker/volumes -v /run/docker/plugins:/run/docker/plugins anybox/buttervolume
$ docker run --privileged -v /var/lib/docker/buttervolumes:/var/lib/docker/buttervolumes -v /run/docker/plugins:/run/docker/plugins anybox/buttervolume

You can also locally install and run the plugin with::

Expand Down Expand Up @@ -126,7 +126,7 @@ You can create a readonly snapshot of the volume with::

$ buttervolume snapshot <volume>

The volumes are currently expected to live in ``/var/lib/docker/volumes`` and
The volumes are currently expected to live in ``/var/lib/docker/buttervolumes`` and
the snapshot will be created in ``/var/lib/docker/snapshots``, by appending the
datetime to the name of the volume, separated with ``@``.

Expand All @@ -142,7 +142,7 @@ or just the snapshots corresponding to a volume with::
$ buttervolume snapshots <volume>

``<volume>`` is the name of the volume, not the full path. It is expected
to live in ``/var/lib/docker/volumes``.
to live in ``/var/lib/docker/buttervolumes``.

Restore a snapshot
------------------
Expand Down Expand Up @@ -174,9 +174,9 @@ container before clonning a volume::
$ buttervolume clone <volume> <new_volume>

``<volume>`` is the name of the volume to be cloned, not the full path. It is expected
to live in ``/var/lib/docker/volumes``.
to live in ``/var/lib/docker/buttervolumes``.
``<new_volume>`` is the name of the new volume to be created as clone of previous one,
not the full path. It is expected to be created in ``/var/lib/docker/volumes``.
not the full path. It is expected to be created in ``/var/lib/docker/buttervolumes``.

Delete a snapshot
-----------------
Expand Down Expand Up @@ -249,7 +249,7 @@ without deleting them::
$ buttervolume purge --dryrun <pattern> <volume>

``<volume>`` is the name of the volume, not the full path. It is expected
to live in ``/var/lib/docker/volumes``.
to live in ``/var/lib/docker/buttervolumes``.

``<pattern>`` is the snapshot retention pattern. It is a semicolon-separated
list of time length specifiers with a unit. Units can be ``m`` for minutes,
Expand Down Expand Up @@ -399,10 +399,10 @@ in a file as follows (tested on Debian 8):
* Stop docker, create required mount point and restart docker::

$ sudo systemctl stop docker \
&& sudo mkdir -p /var/lib/docker/volumes \
&& sudo mkdir -p /var/lib/docker/buttervolumes \
&& sudo mkdir -p /var/lib/docker/snapshots \
&& sudo mkdir -p /var/lib/docker/received \
&& sudo mount -o loop,subvol=volumes /var/lib/docker/btrfs.img /var/lib/docker/volumes \
&& sudo mount -o loop,subvol=volumes /var/lib/docker/btrfs.img /var/lib/docker/buttervolumes \
&& sudo mount -o loop,subvol=snapshots /var/lib/docker/btrfs.img /var/lib/docker/snapshots \
&& sudo mount -o loop,subvol=received /var/lib/docker/btrfs.img /var/lib/docker/received \
&& sudo systemctl start docker
Expand All @@ -412,7 +412,7 @@ in a file as follows (tested on Debian 8):


$ sudo systemctl stop docker \
&& sudo umount /var/lib/docker/volumes \
&& sudo umount /var/lib/docker/buttervolumes \
&& sudo umount /var/lib/docker/snapshots \
&& sudo umount /var/lib/docker/received \
&& sudo systemctl start docker \
Expand Down
5 changes: 5 additions & 0 deletions buttervolume/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from bottle import app
from buttervolume.plugin import jsonloads, SCHEDULE
from buttervolume.plugin import SCHEDULE_LOG, SNAPSHOTS_PATH
from buttervolume.plugin import VOLUMES_PATH
from datetime import datetime, timedelta
from subprocess import CalledProcessError
from threading import Timer
Expand Down Expand Up @@ -126,6 +127,7 @@ def restore(args):
print(res)
return res


def clone(args):
resp = Session().post(
'http+unix://{}/VolumeDriver.Clone'
Expand Down Expand Up @@ -290,6 +292,9 @@ def scheduler(config=SCHEDULE, test=False):


def run(args):
if not os.path.exists(VOLUMES_PATH):
log.info('Creating %s', VOLUMES_PATH)
os.makedirs(VOLUMES_PATH, exist_ok=True)
if not os.path.exists(SNAPSHOTS_PATH):
log.info('Creating %s', SNAPSHOTS_PATH)
os.makedirs(SNAPSHOTS_PATH, exist_ok=True)
Expand Down
6 changes: 3 additions & 3 deletions buttervolume/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from bottle import request, route
from buttervolume import btrfs
from datetime import datetime
from os.path import join, basename, exists, dirname
from subprocess import check_call, CalledProcessError
from os.path import join, basename, dirname
from subprocess import CalledProcessError
from subprocess import run, PIPE
logging.basicConfig(level=logging.INFO)
log = logging.getLogger()

# absolute path to the volumes
VOLUMES_PATH = "/var/lib/docker/volumes/"
VOLUMES_PATH = "/var/lib/docker/buttervolumes/"
SNAPSHOTS_PATH = "/var/lib/docker/snapshots/"
TEST_REMOTE_PATH = "/var/lib/docker/received/"
SCHEDULE = "/etc/buttervolume/schedule.csv"
Expand Down

0 comments on commit 32d4bc3

Please sign in to comment.