DEV Community

klo2k
klo2k

Posted on

4 1 1

Convert directory into BTRFS subvolume

I've been using BTRFS for development and am loving the simplicity and features it provides.

One thing I do a lot is database snapshot on docker volume (to test db migration) - which I can easily do with BTRFS.

Here's how:

  1. Convert docker volume directory into BTRFS subvolume
  2. Snapshot the docker volume (now a BTRFS subvolume)

Convert docker volume directory into BTRFS subvolume

# Directory to convert into BTRFS subvolume
dirPath='/var/lib/docker/test_docker_volume'

# Rename original dierctory
mv "${dirPath}" "${dirPath}_original"

# Create btrfs subvolume
btrfs subvolume create "${dirPath}"

# Copy as "reflink" for speed and save space
cp --archive --one-file-system --reflink=always \
  "${dirPath}_original/." "${dirPath}"

# Remove old directory
rm -rf --one-file-system "${dirPath}_original"
Enter fullscreen mode Exit fullscreen mode

Snapshot the docker volume

Create a read-only snapshot of test_docker_volume docker volume:

btrfs subvolume snapshot -r \
  /var/lib/docker/test_docker_volume \
  /var/lib/docker/test_docker_volume_bak
Enter fullscreen mode Exit fullscreen mode

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
lulonaut profile image
Lulonaut

Thank you!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay