#!/bin/bash
# /usr/local/bin/darchive
# http://crystalfaeries.net/posix/bin/darchive
# celeste:crystalfaery 2016-06-26 16:24:13+00:00
# currently configured to be invoked by /etc/cron.d/rsnapshot
# http://crystalfaeries.net/posix/etc/cron.d/rsnapshot
#30 04 * * 0 root /usr/local/bin/darchive >> /var/log/dar.log 2>&1 || /usr/bin/tail /var/log/dar.log | /usr/bin/mail -s "darchive errs: `hostname`" root
# dar target directory:
darget=/var/cache/dar
# uncomment this version for darchives of rsnapshots
file_system="$(grep snapshot_root /etc/rsnapshot.conf|head -n 1|cut -f 2|sed 's/\/$//')/hourly.0"
# uncomment this version for darchives of the live filesystem
# file_system="/"
if [[ $# -gt 0 ]]
then # we have an argument
if [ "$1" == "--dry-run" ]
then # we recognize it as a dry-run request
dry_run="-e -v" # dry run arguments for dar
shift # we have consumed the argument
else # unrecognized argument
echo "$0: Argument Unrecognized." 1>&2
exit 1 # error exit on bad argument
fi
else # no arguments
dry_run="" # go for it
fi
/usr/local/bin/now >> /var/log/dar.log # time tag the beginning of this execution
mkdir -p $darget/$(/bin/hostname) >> /var/log/dar.log 2>&1
# /usr/bin/time /usr/bin/nice /usr/bin/ionice -c 3 /usr/bin/dar --create \
/usr/bin/time /usr/bin/nice /usr/bin/dar --create \
$darget/$(/bin/hostname)/$(/usr/local/bin/now -h) \
--fs-root $file_system \
--no-warn=all --key :$(/bin/cat /etc/darkey) \
--exclude-from-file /etc/darexclude --slice 2G \
--cache-directory-tagging $dry_run >> /var/log/dar.log 2>&1
/usr/local/bin/now >> /var/log/dar.log # time tag the end of this execution
exit
syntax highlighted by Code2HTML, v. 0.9.1