forked from omniti-labs/zetaback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decodefs.in
executable file
·99 lines (90 loc) · 2.21 KB
/
decodefs.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl
# vim: sts=2 sw=2 ts=8 et
# Copyright (c) 2007 OmniTI Computer Consulting, Inc. All rights reserved.
# For information on licensing see:
# https://labs.omniti.com/zetaback/trunk/LICENSE
use strict;
use warnings;
use Getopt::Long;
use MIME::Base64;
use vars qw/$FS $CONF %conf/;
sub fs_encode($) {
my $d = shift;
my $e = encode_base64($d, '');
$e =~ s/\//_/g;
$e =~ s/=/-/g;
$e =~ s/\+/\./g;
return $e;
}
sub fs_decode($) {
my $e = shift;
$e =~ s/_/\//g;
$e =~ s/-/=/g;
$e =~ s/\./\+/g;
return decode_base64($e);
}
$CONF = qq^__PREFIX__/etc/zetaback.conf^;
GetOptions (
"c=s" => \$CONF,
"f=s" => \$FS
);
my $str_re = qr/(?:"(?:\\\\|\\"|[^"])*"|\S+)/;
my $kvp_re = qr/($str_re)\s*=\s*($str_re)/;
my $stanza_re = qr/($str_re)\s*\{((?:\s*$kvp_re)*)\s*\}/;
sub parse_config() {
local($/);
$/ = undef;
open(CONF, "<$CONF") || die "Unable to open config file: $CONF";
my $file = <CONF>;
# Rip comments
$file =~ s/^\s*#.*$//mg;
while($file =~ m/$stanza_re/gm) {
my $scope = $1;
my $filepart = $2;
$scope =~ s/^"(.*)"$/$1/;
$conf{$scope} ||= {};
while($filepart =~ m/$kvp_re/gm) {
my $key = $1;
my $value = $2;
$key =~ s/^"(.*)"$/$1/;
$value =~ s/^"(.*)"$/$1/;
$conf{$scope}->{lc($key)} = $value;
}
}
close(CONF);
}
sub get_fs_from_mountpoint($) {
my ($mountpoint) = @_;
my $fs;
my $rv = open(ZFSLIST, "__ZFS__ list -t filesystem -H |");
die "Unable to determine zfs filesystem for $mountpoint" unless $rv;
while (<ZFSLIST>) {
my @F = split(' ');
if ($F[-1] eq $mountpoint) {
$fs = $F[0];
last;
}
}
close(ZFSLIST);
die "Unable to determine zfs filesystem for $mountpoint" unless $fs;
return $fs;
}
unless ($FS) {
parse_config;
$FS = $conf{'default'}->{'store'};
$FS =~ s/\/?%h//;
$FS = get_fs_from_mountpoint($FS);
}
print "Decoding filesystems for $FS\n";
my $rv = open(ZFSLIST, "__ZFS__ list -H -r -t snapshot $FS |");
while (<ZFSLIST>) {
my @parts = split();
my $efs = $parts[0];
$efs =~ s/.*\///g;
$efs =~ s/@.*$//;
#print "$efs\n";
my $dfs = fs_decode($efs);
if ($dfs) {
print "$dfs\n $efs\n\n";
}
}