summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 3eb7ea9f695fbeaca7b1bc68e719a3dad7373284 (plain)
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
# Maintainer: Cody Schafer <aur@codyps.com>
# Maintainer: Mike Swanson <mikeonthecomputer@gmail.com>

pkgname=zfs-auto-snapshot
pkgdesc="Implementation of a snapshotting service for ZFS"
pkgver=1.2.1.1
pkgrel=1
arch=('any')
url="https://github.com/zfsonlinux/zfs-auto-snapshot"
license=('GPL2')
depends=('systemd>=212' 'zfs')
makedepends=('git')
source=('git+https://github.com/zfsonlinux/zfs-auto-snapshot#commit=63e4438edb618066e9cc4303df4a7c1331d26654')
sha256sums=('SKIP')

build() {
  cd "$srcdir/$pkgname"

  ### COMMENT the following 4 lines to NOT change the snapshot name to
  ### @PREFIX_DATE_LABEL instead of @PREFIX-LABEL_DATE
  ### (the following makes the snapshots nicely sorted by time)
  sed -r -i \
      -e 's@^(SNAPNAME="\$)(opt_prefix)(.*)-\$DATE@\1{\2}_$DATE\3@' \
      -e 's@^(SNAPGLOB="\$)(opt_prefix)(.*})([?]+)@\1{\2}\4\3@' \
      src/zfs-auto-snapshot.sh

  ### Fix --fast mode sorting improperly when the patch above is applied
  patch -p1 -N <<'EOF'
--- a/src/zfs-auto-snapshot.sh
+++ b/src/zfs-auto-snapshot.sh
@@ -375,3 +375,3 @@ if [ -n "$opt_fast_zfs_list" ]
 then
-	SNAPSHOTS_OLD=$(env LC_ALL=C zfs list -H -t snapshot -o name -s name|grep $opt_prefix |awk '{ print substr( $0, length($0) - 14, length($0) ) " " $0}' |sort -r -k1,1 -k2,2|awk '{ print substr( $0, 17, length($0) )}') \
+	SNAPSHOTS_OLD=$(env LC_ALL=C zfs list -H -t snapshot -o name -s name | grep $opt_prefix | sort -t'@' -k2r,2 -k1,1) \
	  || { print_log error "zfs list $?: $SNAPSHOTS_OLD"; exit 137; }
EOF


  mkdir -p systemd
  ### "Label|NumberOfKeptSnapshots|systemd-timer-spec" of snapshots,
  ### eg. timer and service files, being created adjust/extend if required
  declare -a arr=(
    "frequent|4|*:0/15"
    "hourly|24|hourly"
    "daily|31|daily"
    "weekly|8|weekly"
    "monthly|12|monthly")

  for i in "${arr[@]}"
  do
    _label="$(echo $i | cut -d'|' -f1)"
    _keep="$(echo $i | cut -d'|' -f2)"
    _OnCalendarSpec="$(echo $i | cut -d'|' -f3)"
    _prefix="--prefix=znap"
    cat > systemd/zfs-auto-snapshot-${_label}.service <<EOF
[Unit]
Description=ZFS $_label snapshot service

[Service]
ExecStart=$_PREFIX/bin/zfs-auto-snapshot --skip-scrub $_prefix --label=$_label --keep=$_keep //
EOF

    # write timer files
    cat > systemd/zfs-auto-snapshot-${_label}.timer <<EOF
# See systemd.timers and systemd.time manpages for details
[Unit]
Description=ZFS $_label snapshot timer

[Timer]
OnCalendar=$_OnCalendarSpec
Persistent=true

[Install]
WantedBy=timers.target
EOF
  done
}

package() {
  cd "$srcdir/$pkgname"

  install -d "$pkgdir/usr/bin"
  install -d "$pkgdir/usr/lib/systemd/system"
  install -d "$pkgdir/usr/share/man/man8"
  install -m 755 src/zfs-auto-snapshot.sh "$pkgdir/usr/bin/zfs-auto-snapshot"
  install -m 644 src/zfs-auto-snapshot.8 "$pkgdir/usr/share/man/man8"
  install -m 644 systemd/* "$pkgdir/usr/lib/systemd/system"
}