-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy
executable file
·54 lines (42 loc) · 1.18 KB
/
copy
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
#!/bin/bash
# © 2015–2016 Sebastián González
# http://www.apache.org/licenses/LICENSE-2.0
set -o errexit
this="$(realpath "$0")"
lib="$(dirname "$this")"
script="$(basename "$this")"
source "$lib/common.sh"
usage() {
cat >&2 <<EOF
Usage: $script <pool> <store>
Copies all subvolumes from <pool> to <store>.
Example: $script /var/backup/home /mnt/external/backup/home
EOF
exit 1
}
(( $# == 2 )) || usage
pool=$(realpath "$1")
store=$(realpath "$2")
use-pool "$pool"
use-pool "$store"
if [ -t 2 ] && command -v bar >/dev/null; then
progress=bar
else
progress=cat
fi
# btrfs quirk: the subvolumes used with 'send' must physically be on disk.
sync
# Copy all subvolumes from $pool to $store,
# proceeding from the oldest to the latest.
copying="Copying the whole of"
while read name; do
if [ ! -d "$store/$name" ]; then
echo "$copying subvolume $name to $store"
inProgress=$store/$name
ionice -c3 btrfs send ${parent:+-p "$parent"} "$pool/$name" | \
$progress | ionice -c3 btrfs receive "$store"
unset inProgress
fi
parent="$pool/$name"
copying="Incrementally copying"
done < <(subvolume-names --ascending "$pool")