Skip to content

Commit defeac8

Browse files
peschmaeDerMolly
authored andcommitted
Add backup cli command, exporting all notes for current user
Signed-off-by: Mathias Petermann <[email protected]>
1 parent 091b375 commit defeac8

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

bin/hedgedoc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Config:
7777
\$HEDGEDOC_CONFIG_DIR (defaults to $XDG_CONFIG_HOME/$SCRIPTNAME)
7878
\$HEDGEDOC_COOKIES_FILE (defaults to \$HEDGEDOC_CONFIG_DIR/key.conf)
7979
80-
Usage examples:
80+
Usage examples:
8181
8282
\$ export HEDGEDOC_SERVER='$HEDGEDOC_SERVER'
8383
\$ export HEDGEDOC_COOKIES_FILE=$HEDGEDOC_COOKIES_FILE
@@ -174,7 +174,7 @@ function import_note() {
174174
echo "Hint: You may need to run '$SCRIPTNAME login' to authenticate first." >&2
175175
return 2
176176
fi
177-
echo "$note_id"
177+
echo "$note_id"
178178
}
179179

180180
function export_note() {
@@ -230,7 +230,7 @@ function export_note() {
230230
output_path="${output_path:-$note_id.zip}"
231231
# hack: there is no way to get slide output as zipfile directly.
232232
# we dump it to folder of html files first then zip it.
233-
233+
234234
# check for any existing conflicting file/dir that wget downloads
235235
local temp_folder_name="$(
236236
echo "$HEDGEDOC_SERVER" \
@@ -259,6 +259,17 @@ function export_note() {
259259
esac
260260
}
261261

262+
function backup_all_notes() {
263+
output_path="${1:-archive.zip}"
264+
265+
curl \
266+
--silent \
267+
--cookie "$HEDGEDOC_COOKIES_FILE" \
268+
--output "$output_path" \
269+
"${HEDGEDOC_SERVER}/me/export" \
270+
&& echo "$output_path"
271+
}
272+
262273
function user_login() {
263274
local method="${1#--}" username="${2:-}" password="${3:-}" username_arg=""
264275
case "$method" in
@@ -349,7 +360,7 @@ function user_profile() {
349360

350361
function user_history() {
351362
assert_is_authenticated
352-
363+
353364
curl \
354365
--silent \
355366
--cookie "$HEDGEDOC_COOKIES_FILE" \
@@ -390,6 +401,9 @@ function main() {
390401
export)
391402
export_note "${1:-}" "${2:-}" "${3:-}"
392403
;;
404+
backup)
405+
backup_all_notes "${1:-}"
406+
;;
393407
delete)
394408
delete_note "${1:-}"
395409
;;
@@ -416,7 +430,7 @@ function main() {
416430
# Do the usage function of no Command line arguments are given.
417431
if [[ $# -eq 0 ]]; then
418432
set -- "help"
419-
fi
433+
fi
420434

421435
# Allow importing funcs without running main by using `source ./bin/hedgedoc --import`
422436
if [[ "${1:-}" != "--import" ]]; then

0 commit comments

Comments
 (0)