Skip to content

Commit 72d2276

Browse files
authored
Merge pull request sysnux#12 from ceremcem/tests-should-pass
Tests should pass
2 parents 15512d6 + eb529d9 commit 72d2276

File tree

4 files changed

+464
-124
lines changed

4 files changed

+464
-124
lines changed

README.md

Lines changed: 52 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,127 +3,81 @@ btrfs-snapshots-diff
33

44
About
55
-----
6-
`btrfs-snapshots-diff.py` is a simple Python2 script that displays the differences
6+
`btrfs-snapshots-diff.py` is a simple Python3 script that displays the differences
77
between two Btrfs snapshots (from the same subvolume obviously).
88

9-
Uses btrfs send to compute the differences, decodes the stream and
9+
Uses `btrfs send --no-data` to compute the differences, decodes the stream and
1010
displays the differences.
1111

12-
Can read data from parent and current snapshots, or from diff file created with:
13-
14-
`btrfs send -p parent chid --no-data -f /tmp/snaps-diff`
15-
1612
Usage
1713
-----
18-
usage: btrfs-snapshots-diff.py [-h] [-p PARENT] [-c CHILD] [-f FILE] [-t] [-a] [-s] [-j] [-b]
19-
20-
Display differences between 2 Btrfs snapshots
21-
22-
optional arguments:
23-
-h, --help show this help message and exit
24-
-p PARENT, --parent PARENT
25-
parent snapshot (must exists and be readonly)
26-
-c CHILD, --child CHILD
27-
child snapshot (will be created if it does not exist)
28-
-f FILE, --file FILE diff file
29-
-t, --filter does not display temporary files, nor all time modifications
30-
(just latest)
31-
-a, --by_path Group commands by path
32-
-s, --csv CSV output
33-
-j, --json JSON output (commands only)
34-
-b, --bogus Add bogus renamed_from action (used only when grouping by path)
35-
36-
37-
Option `--json` (`-j`), available for commands only, will output a list of
14+
usage: btrfs-snapshots-diff.py [options] -p PARENT -c CHILD
15+
btrfs-snapshots-diff.py [options] -f FILE
16+
17+
Display differences between 2 Btrfs snapshots
18+
19+
optional arguments:
20+
-h, --help Show this help message and exit
21+
-p, --parent PATH Path to PARENT (older) snapshot (must be readonly)
22+
-c, --child PATH Path to CHILD (newer) snapshot
23+
-f, --file FILE Path to diff file generated by
24+
"btrfs send --no-data -p first second > FILE"
25+
-t, --filter Do not display temporary files or any time modifications (just latest)
26+
-a, --by_path Group commands by path
27+
-s, --csv CSV output
28+
-j, --json JSON output (commands only)
29+
-b, --bogus Add bogus renamed_from action (used only when grouping by path)
30+
31+
32+
* `--json` (`-j`), available for commands only, will output a list of
3833
commands in JSON format.
3934

40-
Option `--csv` (`-s`) will produce on line for each modification, instead of
35+
* `--csv` (`-s`) will produce on line for each modification, instead of
4136
formatted output: the first column is the path, then each action taken on the
4237
file is in a new column. Separator is ";".
4338

44-
Option `--by_path` (`-a`) groups command by path, giving a better view of what
39+
* `--by_path` (`-a`) groups command by path, giving a better view of what
4540
happenned on the file system.
4641

47-
`--bogus` (`-b`) adds a bogus command to the stream, to better track renaming of
42+
* `--bogus` (`-b`) adds a bogus command to the stream, to better track renaming of
4843
files / dir (only usefull with `--by_path`).
4944

50-
With option `--filter` (`-t`), the script tries to be a bit smarter (only usefull
45+
* With option `--filter` (`-t`), the script tries to be a bit smarter (only usefull
5146
with `--by_path`):
52-
* it does not display temporary files created by send stream,
53-
* it displays 'created' or 'rewritten' on the files renamed from temporary files,
54-
* it displays only the latest time modifications, if there are two or more.
47+
* it does not display temporary files created by send stream,
48+
* it displays 'created' or 'rewritten' on the files renamed from temporary files,
49+
* it displays only the latest time modifications, if there are two or more.
5550

5651
Example
5752
-------
58-
The example below is the result of creating a new subvolume, taking a
59-
snapshot (parent), creating some objects ( a file called "file", a
60-
directory called "dir", fifo, link and symlink...), then taking a new snapshot,
61-
and last calling btrfs-snapshots-diff to display the differences (see test.sh).
53+
See [./tests.output](./tests.output) file as an example output. These outputs are created regarding to
54+
the changes made by [./tests.sh](./tests.sh):
55+
56+
```bash
57+
touch file
58+
mkdir dir
59+
mkfifo fifo
60+
ln file hardlink
61+
ln -s file symlink
62+
echo 'Hello Btrfs' > 'xxx;yyy;zzz'
63+
mv file file2
64+
```
65+
66+
Tests
67+
-----
6268

63-
sudo ./btrfs-snapshots-diff.py -p btrfs-diff-tests.parent -c btrfs-diff-tests.child
64-
Found a valid Btrfs stream header, version 1
65-
66-
btrfs-diff-tests.child
67-
snapshot: uuid=d6515a0a57d462449bcc9c2533d01277, ctrasid=171948, clone_uuid=b66a4f902e348b46b87d4cb85d967ad9, clone_ctransid=171945
68-
69-
__sub_root__
70-
times a=2016/04/03 10:36:13 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
71-
times a=2016/04/03 10:36:13 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
72-
times a=2016/04/03 10:36:13 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
73-
times a=2016/04/03 10:36:13 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
74-
times a=2016/04/03 10:36:13 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
75-
times a=2016/04/03 10:36:13 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
76-
77-
o257-171948-0
78-
mkfile
79-
rename to "file"
80-
81-
file
82-
renamed from "o257-171948-0"
83-
xattr security.selinux 28277
84-
truncate 0
85-
owner 1000:1000
86-
mode 664
87-
times a=2016/04/03 10:36:15 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
88-
89-
hardlink
90-
link to "file"
91-
92-
o258-171948-0
93-
mkdir
94-
rename to "dir"
95-
96-
dir
97-
renamed from "o258-171948-0"
98-
xattr security.selinux 28277
99-
owner 1000:1000
100-
mode 775
101-
times a=2016/04/03 10:36:15 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
102-
103-
o259-171948-0
104-
mkfifo
105-
rename to "fifo"
106-
107-
fifo
108-
renamed from "o259-171948-0"
109-
xattr security.selinux 28277
110-
owner 1000:1000
111-
mode 664
112-
times a=2016/04/03 10:36:15 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
113-
114-
o260-171948-0
115-
symlink to "file"
116-
rename to "symlink"
117-
118-
symlink
119-
renamed from "o260-171948-0"
120-
xattr security.selinux 28277
121-
owner 1000:1000
122-
times a=2016/04/03 10:36:15 m=2016/04/03 10:36:15 c=2016/04/03 10:36:15
69+
```bash
70+
./tests.sh > tests.output
71+
git diff # inspect visually, there should be no unexpected changes. See issue#13.
72+
git checkout -- tests.output
73+
```
12374

12475
Requirements
12576
------------
126-
No requirements besides Python-3!
77+
78+
```
79+
apt-get install jq
80+
```
12781

12882
Bugs
12983
----

btrfs-snapshots-diff.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env python
1+
#! /usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
44

@@ -592,6 +592,7 @@ def main():
592592
'-f',
593593
stream_file,
594594
args.child,
595+
'-q',
595596
]
596597
try:
597598
subprocess.check_call(cmd)

0 commit comments

Comments
 (0)