Skip to content

Instantly share code, notes, and snippets.

@AngryAnt
Created December 11, 2019 08:20
Show Gist options
  • Save AngryAnt/89cfb92467053db5c2d436026869f202 to your computer and use it in GitHub Desktop.
Save AngryAnt/89cfb92467053db5c2d436026869f202 to your computer and use it in GitHub Desktop.
User callback script for BackInTime handling mount & unmount of encrypted backup target and using the modify date of a file to communicate last snapshot date.
#!/bin/bash
# Copyright (c) 2012-2015 Germar Reitze
# Mount/unmount implementation 2019 Emil "AngryAnt" Johansen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#Script should return 0 if everything is alright. Returncode !0 will cancle
#the running snapshot (BIT version >1.1.0).
profile_id="$1"
profile_name="$2"
reason="$3"
device="SPECIFY"
key_path="SPECIFY"
mapname="back-in-time"
mount_dir="/mnt/back-in-time"
last_snapshot_file="SPECIFY"
case $reason in
1) #Backup process begins
;;
2) #Backup process ends
;;
3) #A new snapshot was taken
snapshot_id="$4"
snapshot_name="$5"
sudo touch $last_snapshot_file
;;
4) #There was an error
errorcode="$4"
case $errorcode in
1) #ERROR The application is not configured
;;
2) #ERROR A 'take snapshot' process is already running
;;
3) #ERROR Can't find snapshots folder (is it on a removable drive ?)
;;
4) #ERROR A snapshot for 'now' already exist
;;
esac
;;
5) #backintime-qt4 (GUI) started
;;
6) #backintime-qt4 (GUI) closed
;;
7) #Mount drives
sudo cryptsetup open $device $mapname --key-file=$key_path && mkdir $mount_dir && mount /dev/mapper/$mapname $mount_dir
;;
8) #Unmount the drives
sudo umount $mount_dir && rm -r $mount_dir
sudo cryptsetup close $mapname
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment