dotfiles/.local/bin/scripts/bog

34 lines
804 B
Plaintext
Raw Normal View History

2022-08-04 21:55:07 +00:00
#!/bin/sh -e
2021-11-25 12:18:57 +00:00
# Simple backup with borg
2021-12-02 22:33:22 +00:00
if test $# -eq 0
2022-08-04 21:55:07 +00:00
then borg list --format "{barchive:40} Created {time}{NL}"
exit $?
2021-12-02 22:33:22 +00:00
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;;
2022-08-04 21:55:07 +00:00
(tree) borg list --short "::$2" | tree --fromfile . | less -F
exit $?;;
(-n) run=arg-test; shift;;
(*_) prefix=$1; shift;;
(*) break;;
esac
done
2021-11-25 12:18:57 +00:00
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" "$@"
2021-11-25 12:18:57 +00:00