hedgebak: back up hedgedoc notes with hedgedoc-cli and git
This commit is contained in:
parent
2462cddbd7
commit
fa22309405
48
hedgebak
Executable file
48
hedgebak
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# uses https://github.com/hedgedoc/cli to download notes as markdown and commit them to a
|
||||||
|
# git repo
|
||||||
|
#
|
||||||
|
# mandatory files in pwd:
|
||||||
|
# .hedgeserver - the URL of the hedgedoc instance
|
||||||
|
# .hedgebak - note IDs to back up
|
||||||
|
# optional:
|
||||||
|
# .hedgecookie - cookie to use (e.g. for owner-accessible notes)
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
ID_FILE=.hedgebak
|
||||||
|
SERVER_FILE=.hedgeserver
|
||||||
|
COOKIE_FILE=.hedgecookie
|
||||||
|
|
||||||
|
if [ ! -d ".git" ]; then
|
||||||
|
echo "not a git repo, exiting"
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$SERVER_FILE" ]; then
|
||||||
|
echo "$SERVER_FILE does not exist, exiting"
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
SERVER=`cat "$SERVER_FILE"`
|
||||||
|
|
||||||
|
HEDGEDOC_COOKIES_FILE=""
|
||||||
|
if [ -f "$COOKIE_FILE" ]; then
|
||||||
|
HEDGEDOC_COOKIES_FILE="$COOKIE_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$ID_FILE" ]; then
|
||||||
|
echo "$ID_FILE does not exist, exiting"
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
while read id; do
|
||||||
|
outfile=`HEDGEDOC_SERVER="$SERVER" HEDGEDOC_COOKIES_FILE="$HEDGEDOC_COOKIES_FILE" hedgedoc export --md "$id"`
|
||||||
|
echo "$outfile"
|
||||||
|
git add "$outfile"
|
||||||
|
done < "$ID_FILE"
|
||||||
|
|
||||||
|
DATE=`date --utc +"%Y%m%d_%H%M"`
|
||||||
|
git commit -m "note backup $DATE (utc)"
|
||||||
|
git push
|
Loading…
Reference in New Issue
Block a user