All of lore.kernel.org
 help / color / mirror / Atom feed
* Creating recursive snapshots for all filesystems
@ 2013-05-02 20:41 Alexander Skwar
  2013-05-03  8:48 ` Sander
  2013-05-05 11:05 ` Kai Krakow
  0 siblings, 2 replies; 18+ messages in thread
From: Alexander Skwar @ 2013-05-02 20:41 UTC (permalink / raw)
  To: linux-btrfs

Hello once more...

I'm on Ubuntu 13.04 with Ubuntu kernel 3.8.0-19-lowlatency and
Btrfs v0.20-rc1.

(Did I say that before...? *G*)

Okay, ATM I'm writing a script for creating snapshots for "backups" of
all my btrfs filesystems. I come from a FreeBSD / Solaris background
with heavy use of ZFS.

In ZFS, it's very easy to create snapshots of all "zpools"
("filesystems") of the system, like so:

SnapName=backup.`date +%Y%m%d--%H%M%S`
zpool list -Ho name | while read zpool; do
  zfs snapshot -r $zpool@$SnapName &
done ; wait

Well… How to do something like this with btrfs? I do _not_ want to
have to manually list the filesystems/subvolumes I've got in some
script or configuration file.

Where I'm hanging right now, is that I can't seem to figure out a
"bullet proof" way to find all the subvolumes of the filesystems I
might have.

I've got this:

root@ask-home:~# btrfs fi show
failed to read /dev/sr0
Label: 'Data'  uuid: 7d2eb10f-aced-4d41-bb7f-7badbf075b6a
Total devices 1 FS bytes used 27.96GB
devid    1 size 35.00GB used 35.00GB path /dev/dm-0

Label: 'KernBtrfs'  uuid: 8b16bc2a-43e3-40da-89f5-7b333c6682f3
Total devices 1 FS bytes used 655.05MB
devid    1 size 11.85GB used 6.04GB path /dev/sda11

Btrfs v0.20-rc1

root@ask-home:~# mount -t btrfs
/dev/mapper/ssd-Data on /data type btrfs (rw,noatime,ssd,discard)
/dev/mapper/ssd-Data on /home type btrfs (rw,noatime,ssd,discard,subvol=home)
/dev/sda11 on /data/Kernel/KernBtrfs type btrfs (rw,noatime)

Now, how would I find all the subvolumes of the btrfs with the label
"Data" (or uuid 7d...) or /dev/dm-0? "btrfs subvolume list" only seems
to operate on where a btrfs is mounted. It works on "path".

I could do "btrfs subv list -a /data", but how would I figure out,
that "/data" is the "root" of the filesystem with uuid 7d...?

For now, I do something like this (-> http://pastebin.com/u08ub1i8):

SnapName=backup.`date +%Y%m%d--%H%M%S`
btrfs fi show 2>/dev/null | awk '/ path / {print $NF}' | while read path; do
  SafePath=`echo "$path" | tr / .`
  TmpMountDir=`mktemp -d /tmp/.btrfs.mount.$SafePath.XXXXXX`
  mount -t btrfs $path $TmpMountDir
  (btrfs subv list -ar $TmpMountDir; btrfs subv list -a $TmpMountDir)
| sort | uniq -u | while read _id Id _gen Gen _top _level Toplevel
_path Path; do
    btrfs subv snaps -r "$TmpMountDir/$Path" "$TmpMountDir/$Path.$SnapName"
  done
  umount $TmpMountDir
  rmdir $TmpMountDir
done

Now, this works, but seems "somewhat" complicated... But
maybe I'm just spoiled by ZFS ;)

Is there an easier way to achieve what I want? I want to achieve:

Creating recursive snapshots for all filesystems

;)

Thanks,

Alexander
--
=>        Google+ => http://plus.skwar.me         <==
=> Chat (Jabber/Google Talk) => a.skwar@gmail.com <==

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2013-05-30 16:40 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-02 20:41 Creating recursive snapshots for all filesystems Alexander Skwar
2013-05-03  8:48 ` Sander
2013-05-03 11:46   ` Alexander Skwar
2013-05-05 11:05 ` Kai Krakow
2013-05-05 12:59   ` Alexander Skwar
2013-05-05 16:03     ` Kai Krakow
2013-05-05 16:19       ` Alexander Skwar
2013-05-09 20:41     ` nocow 'C' flag ignored after balance Kyle Gates
2013-05-10  5:15       ` Liu Bo
2013-05-10 13:58         ` Kyle Gates
2013-05-16 19:11           ` Kyle Gates
2013-05-17  7:04             ` Liu Bo
2013-05-17 14:38               ` Kyle Gates
2013-05-28 14:22               ` Kyle Gates
2013-05-29  1:55                 ` Liu Bo
2013-05-29  8:33                   ` Miao Xie
2013-05-30 16:40                     ` Kyle Gates
2013-05-30 16:40                   ` Kyle Gates

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.