diff --git a/.gitignore b/.gitignore index b94b850..2ad8397 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,14 @@ .directory -debian/apt-btrfs-snapshot* -debian/.debhelper* +debian/.debhelper debian/files +debian/apt-btrfs-snapshot* apt-btrfs-snapshot-build-deps_*.deb build-ppa.sh !debian/build-ppa.sh *.kate-swp +build +*.egg-info +.pybuild/* + +# ignore autogenerated pot files +po/apt-btrfs-snapshot.pot diff --git a/README.md b/README.md new file mode 100644 index 0000000..45078c5 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# apt-btrfs-snapshot fork + +## Changes in the fork + +Changes compared to the upstream version 3.5.1: + +* Systemd daily timer instead of weekly cron to clean old snapshots +* Do not run the timer when on battery (with no AC power) +* Force btrfs sync after snapshot deletions +* Introduce etc/apt-btrfs-snapshot.conf.d/ directory for config files which are loaded in alpha-numerical order +* /etc/apt-btrfs-snapshot.conf.d/10-default.conf is the default config, but other packages may put other configs into the config directory (for example, I want to override MaxAge on a group of machines and package my own config file /etc/apt-btrfs-snapshot.conf.d/20-my.conf); I will probably add such config to [system-autoupdate](https://gitlab.com/mikhailnov/system-autoupdate) +* Default MageAge to 15 days (2 weeks + 1 day) instead of 90 days to reduce problems with no empty space left on disk +* Drop support for building with python2 + +## Installation +Use [ppa:mikhailnov/utils](https://launchpad.net/~mikhailnov/+archive/ubuntu/utils/) or deb package attached in [Tags](https://gitlab.com/mikhailnov/apt-btrfs-snapshot/tags). + diff --git a/data/10-default.conf b/data/10-default.conf new file mode 100644 index 0000000..4ca274c --- /dev/null +++ b/data/10-default.conf @@ -0,0 +1,2 @@ +# snapshots older than $MaxAge days will be removed automatically by a daily systemd timer apt-btrfs-snapshot-sanity.timer +MaxAge=15 diff --git a/data/apt-btrfs-snapshot-sanity b/data/apt-btrfs-snapshot-sanity new file mode 100644 index 0000000..8525ff6 --- /dev/null +++ b/data/apt-btrfs-snapshot-sanity @@ -0,0 +1,26 @@ +#!/bin/sh + +set -e + +# check if its there +if [ ! -x /usr/bin/apt-btrfs-snapshot ]; then + exit 0 +fi + +# check if its usable, if list returns a non-zero exit code, +# we probably run on a system with no snapshot support +if ! /usr/bin/apt-btrfs-snapshot list > /dev/null 2>&1; then + exit 0 +fi + +# configs from /etc/apt-btrfs-snapshot.conf.d/ are loaded (sources) in an alpha-numerical order (as `ls -1v`) +MaxAge=15 +eval $(apt-config shell MaxAge APT::Snapshots::MaxAge) +for i in $(/bin/ls -1v /etc/apt-btrfs-snapshot.conf.d/*.conf) +do + . "$i" +done + +# delete old snapshots +apt-btrfs-snapshot delete-older-than "${MaxAge}d" + diff --git a/data/apt-btrfs-snapshot-sanity.service b/data/apt-btrfs-snapshot-sanity.service new file mode 100644 index 0000000..f722119 --- /dev/null +++ b/data/apt-btrfs-snapshot-sanity.service @@ -0,0 +1,10 @@ +[Unit] +Description=Clean old BTRFS snapshots made by apt-btrfs-snapshot +ConditionACPower=true + +[Service] +StandardOutput=journal +StandardError=journal +Type=oneshot +ExecStart=/usr/bin/apt-btrfs-snapshot-sanity +ExecStartPost=/bin/btrfs filesystem sync '/' diff --git a/data/apt-btrfs-snapshot-sanity.timer b/data/apt-btrfs-snapshot-sanity.timer new file mode 100644 index 0000000..620bb30 --- /dev/null +++ b/data/apt-btrfs-snapshot-sanity.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Clean old BTRFS snapshots made by apt-btrfs-snapshot + +[Timer] +OnCalendar=daily +AccuracySec=12h +RandomizedDelaySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/debian/build-ppa.sh b/debian/build-ppa.sh new file mode 100755 index 0000000..021eccc --- /dev/null +++ b/debian/build-ppa.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Written and used by Mikhail Novosyolov for building the apt-btrfs-snapshot package to the Launchpad.net PPA repository for Ubuntu and Debian +# Open-sourced to allow other people do the same easily +# Thanks to Denis Linvinus for the base of this script + +pkg_name="apt-btrfs-snapshot" + +# this allows the script to be ran both from the root of the source tree and from ./debian directory +dir_start="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +if [ "$(basename "${dir_start}")" = 'debian' ]; then + cd .. +fi +dir0="$(pwd)" +old_header=$(head -1 ./debian/changelog) + +for i in xenial artful bionic cosmic +do + old_version="$(cat ./debian/changelog | head -n 1 | awk -F "(" '{print $2}' | awk -F ")" '{print $1}')" + new_version="${old_version}~${i}1" + sed -i -re "s/${old_version}/${new_version}/g" ./debian/changelog + sed -i -re "1s/unstable/$i/" ./debian/changelog + # -I to exclude .git; -d to allow building .changes file without build dependencies installed + dpkg-buildpackage -I -S -sa -d + sed -i -re "1s/.*/${old_header}/" ./debian/changelog + cd .. + + # change PPA names to yours, you may leave only one PPA; I upload hw-probe to 2 different PPAs at the same time + for reponame in "ppa:mikhailnov/utils" + do + dput -f "$reponame" "$(ls -tr ${pkg_name}_*_source.changes | tail -n 1)" + done + + cd "$dir0" + sleep 1 +done + +cd "$dir_start" diff --git a/debian/changelog b/debian/changelog index 24ae701..a744e1e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +apt-btrfs-snapshot (2:3.6-2) unstable; urgency=medium + + * Systemd daily timer instead of weekly cron to clean old snapshots + * Do not run the timer when on battery (with no AC power) + * Force btrfs sync after snapshot deletions + * Introduce etc/apt-btrfs-snapshot.conf.d/ directory for config files which are loaded in alpha-numerical order + * /etc/apt-btrfs-snapshot.conf.d/10-default.conf is the default config, but other packages may put other configs into the config directory (for example, I want to override MaxAge on a group of machines and package my own config file /etc/apt-btrfs-snapshot.conf.d/20-my.conf) + * Default MageAge to 15 days (2 weeks + 1 day) instead of 90 days to reduce problems with no empty space left on disk + * Drop support for building with python2 + + -- Mikhail Novosyolov Fri, 22 Jun 2018 19:58:00 +0300 + apt-btrfs-snapshot (3.5.1) yakkety; urgency=medium * fix mock of "btrfs" binary diff --git a/debian/compat b/debian/compat index 7f8f011..ec63514 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -7 +9 diff --git a/debian/control b/debian/control index 7e0f72e..575cf25 100644 --- a/debian/control +++ b/debian/control @@ -6,11 +6,8 @@ Build-Depends: debhelper (>= 7.0.50~), python3-all, python3-distutils-extra, python3-mock, - pyflakes, - python (>= 2.6.5-2~), - python-distutils-extra, - python-mock, - pep8, + python3-pyflakes, + python3-pep8, X-Python-Version: all X-Python3-Version: >= 3.2 Standards-Version: 3.9.3 @@ -18,9 +15,9 @@ Vcs-Bzr: https://code.launchpad.net/apt-btrfs-snapshot Package: apt-btrfs-snapshot Architecture: all -Depends: ${python:Depends}, - ${python3:Depends}, +Depends: ${python3:Depends}, ${misc:Depends}, + python3-distutils, btrfs-tools Description: Automatically create snapshot on apt operations This will create a btrfs snapshot of the root filesystem each time diff --git a/debian/install b/debian/install index 310bf6e..e055e82 100644 --- a/debian/install +++ b/debian/install @@ -1 +1,5 @@ -data/80-btrfs-snapshot etc/apt/apt.conf.d/ +data/80-btrfs-snapshot /etc/apt/apt.conf.d/ +data/apt-btrfs-snapshot-sanity /usr/bin/ +data/apt-btrfs-snapshot-sanity.service /lib/systemd/system/ +data/apt-btrfs-snapshot-sanity.timer /lib/systemd/system/ +data/10-default.conf /etc/apt-btrfs-snapshot.conf.d/ diff --git a/debian/rules b/debian/rules index 04df1bf..cd2262c 100755 --- a/debian/rules +++ b/debian/rules @@ -1,29 +1,4 @@ #!/usr/bin/make -f -PYTHON2:=$(shell pyversions -r) -PYTHON3:=$(shell py3versions -r) -py3sdo=set -e; $(foreach py, $(PYTHON3), $(py) $(1);) -pyalldo=set -e; $(foreach py, $(PYTHON2) $(PYTHON3), $(py) $(1);) - +#export DH_VERBOSE=255 %: - dh $@ --with python2,python3 - -ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) -override_dh_auto_test: - $(call pyalldo, -m unittest discover -vv test/) -endif - -override_dh_auto_build: - dh_auto_build - $(call py3sdo, setup.py build) - -override_dh_auto_install: - dh_auto_install - $(call py3sdo, setup.py install --root=$(CURDIR)/debian/apt-btrfs-snapshot --install-layout=deb) - -override_dh_auto_clean: - dh_auto_clean - rm -rf build - rm -rf *.egg-info - -override_dh_python3: - dh_python3 --shebang=/usr/bin/python3 + dh $@ --with python3,systemd --buildsystem=pybuild diff --git a/debian/source/format b/debian/source/format deleted file mode 100644 index 89ae9db..0000000 --- a/debian/source/format +++ /dev/null @@ -1 +0,0 @@ -3.0 (native) diff --git a/setup.py b/setup.py index 0f7d520..368449c 100755 --- a/setup.py +++ b/setup.py @@ -1,11 +1,11 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from distutils.core import setup from DistUtilsExtra.command import build_i18n, build_extra setup( name='apt-btrfs-snapshot', - version='0.1', + version='3.6', author='Michael Vogt', url='http://launchpad.net/apt-btrfs-snapshot', scripts=['apt-btrfs-snapshot'],