From abd08d10c37904bfff0c8c53f225380c2bd37d03 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 2 Jul 2014 16:07:25 +0200 Subject: [PATCH] move backup to duplicity --- backup | 68 +++++++++++++++++++------------------------------- postinst-setup | 8 +----- preinst-backup | 7 ------ 3 files changed, 26 insertions(+), 57 deletions(-) diff --git a/backup b/backup index db4faaa..0518410 100755 --- a/backup +++ b/backup @@ -1,46 +1,28 @@ -#!/bin/sh -e - -# call rsnapshot daily/weekly/monthly regularly -# this should be called from cron very often (several times a day) to not miss -# a cycle when the machine is powered down for extended times. -# -# Author: Martin Pitt -# License: Public Domain - -backupdir=`grep ^snapshot_root ~/.rsnapshotrc | awk '{print $2}'` - -now=`date +%s` - -get_age() { - if [ -e $backupdir/$1 ]; then - age=$(($now - `stat -c %Y $backupdir/$1`)) - else - unset age +#!/bin/sh +set -eu +cd $HOME +LOG=.cache/duplicity/log + +# do backup every day +if [ -e "$LOG" ] && [ $(( `date +%s` - `stat -c %Y $LOG` )) -lt 86300 ]; then + exit 0 +fi + +# figure out $DISPLAY when running from cron +if [ -z "${DISPLAY:-}" ]; then + socket="/run/user/`id -u`/X11-display" + if [ -L "$socket" ]; then + socket=$(readlink "$socket") + export DISPLAY=:${socket##*/X} fi -} - -# abort if last backup was less than a day ago -get_age daily.0 -[ -n "$age" ] && [ $age -lt 86300 ] && exit 0 - -print '------------1---------------' -# monthly backup if last monthly is older than a month (if it doesn't exist, -# check oldest weekly) -get_age monthly.0 -[ -n "$age" ] || get_age weekly.3 -[ -n "$age" ] && [ $age -ge 2591900 ] && mode=monthly - -# weekly backup if last weekly is older than a week (if it doesn't exist, -# check oldest daily) -get_age weekly.0 -[ -n "$age" ] || get_age daily.6 -[ -n "$age" ] && [ $age -ge 604700 ] && mode=weekly +fi -# default to daily -[ -n "$mode" ] || mode=daily +if ! ip route | grep -q '^default.*wlan'; then + notify-send "Backup skipped, not on WLAN" + exit 0 +fi -# call rsnapshot -echo mode: $mode -#notify-send "$mode backup started" || : -rsnapshot -c ~/.rsnapshotrc $mode -#notify-send "$mode backup finished" || : +notify-send "Backup started" +mkdir -p $(dirname $LOG) +env PASSPHRASE="$(cat ~/.backup-passphrase)" duplicity --full-if-older-than 1M --exclude-globbing-filelist .duplicity-ignore . rsync://piware.de/backup/donald >> $LOG || { notify-send "BACKUP FAILED!"; exit 1; } +notify-send "Backup finished successfully" diff --git a/postinst-setup b/postinst-setup index 5391e89..86eb843 100755 --- a/postinst-setup +++ b/postinst-setup @@ -1,11 +1,5 @@ #!/bin/sh -e -# move backup to /var -if [ -d /home/martin/backup ] && [ ! -d /var/backups/martin ]; then - cp -a /home/martin/backup /var/backups/martin - rm -rf /home/martin/backup -fi - # need bzr and postfix for the setup below DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends postfix openssh-server bzr python-paramiko apt-cacher-ng @@ -50,7 +44,7 @@ apt-get purge -y --auto-remove hplip hplip-data printer-driver-hpcups brltty blu killall apt-get || true apt-get update -DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y --force-yes vim patchutils offlineimap diffstat gtimelog devhelp python3-doc manpages-dev weechat weechat-plugins weechat-scripts listadmin quilt mutt editmoin lintian ubuntu-dev-tools dput easytag rsnapshot texlive-lang-german texlive-latex-extra powertop qemu-kvm qemu-utils bzr-buildpackage git build-essential fakeroot devscripts libglib2.0-doc libgtk-3-doc git-buildpackage d-feet wmctrl libnotify-bin svn-buildpackage pastebinit lptools openvpn pdfjam sbuild schroot exiv2 phablet-tools gstreamer1.0-plugins-ugly flashplugin-installer valgrind calibre autopkgtest +DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y --force-yes vim patchutils offlineimap diffstat gtimelog devhelp python3-doc manpages-dev weechat weechat-plugins weechat-scripts listadmin quilt mutt editmoin lintian ubuntu-dev-tools dput easytag texlive-lang-german texlive-latex-extra powertop qemu-kvm qemu-utils bzr-buildpackage git build-essential fakeroot devscripts libglib2.0-doc libgtk-3-doc git-buildpackage d-feet wmctrl libnotify-bin svn-buildpackage pastebinit lptools openvpn pdfjam sbuild schroot exiv2 phablet-tools gstreamer1.0-plugins-ugly flashplugin-installer valgrind calibre autopkgtest apt-get install lxc # ccache diff --git a/preinst-backup b/preinst-backup index c19559d..eef4f5f 100755 --- a/preinst-backup +++ b/preinst-backup @@ -7,10 +7,3 @@ fi # push /etc/ (cd /etc; HOME=/home/martin bzr push) - -# copy backup to ~ -if [ -d /home/martin/backup ]; then - echo "/home/martin/backup exists already, aborting" >&2 - exit 1 -fi -[ ! -d /var/backups/martin/ ] || cp -a /var/backups/martin/ /home/martin/backup -- 2.39.2