dotfiles/.local/bin/scripts/bog

35 lines
894 B
Bash
Executable File

#!/bin/sh -e
# Simple backup with borg
if test $# -eq 0
then echo "To backup: bog [prefix_] folder"
borg list --format "{barchive:40} Created {time}{NL}"
exit $?
fi
while test $# -gt 0; do
case "$1" in
(mount) moul backup >/dev/null 2>&1
cd /mnt/backup
mkdir -p backups
borg mount borg backups
cd backups
"$SHELL"
cd ..
borg umount backups
rm -d backups
exit 0;;
(tree) borg list --short $(case $2 in (*::*) echo "$2";; (*) echo "::$2";; esac) | tree --fromfile . | less -F
exit $?;;
(-n) run=arg-test; shift;;
(*_) prefix=$1; shift;;
(*) break;;
esac
done
name="$(echo "$1" |
sed -e 's|/$||' \
-e 's|20\([0-9]\{2\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\)|\1\2\3|' \
-e 's|\([0-9]\{6\}\)[-_]\(.*\)|\2_\1|' \
-e 's|\(\w\+Drive\)|cloud_\L\1|i')"
test $# -gt 1 && shift
${run:-borg} create --exclude-caches --progress --stats "::$prefix$name" "$@"