From 5d9ec65d9f63e4f1f928eecb11fce55c67ec8305 Mon Sep 17 00:00:00 2001 From: "committer@tuxwarrior" Date: Thu, 26 Feb 2026 14:57:45 -0500 Subject: [PATCH] + notesArchiver.sh --- dots/bash/.bashrc | 1 - dots/bin/notesArchiver.sh | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 dots/bin/notesArchiver.sh diff --git a/dots/bash/.bashrc b/dots/bash/.bashrc index 8531007..ee3369c 100644 --- a/dots/bash/.bashrc +++ b/dots/bash/.bashrc @@ -361,7 +361,6 @@ nas() { # } #alias videoCompressor="/home/poq/syncDir/gitRepos/gi.op.fo/miniProjects/2104_videoCompressor/src/vc_v2.sh" # alias videoWatermark="/home/poq/syncDir/gitRepos/gi.op.fo/miniProjects/2104_videoCompressor/src/vcwm_v1.sh" -#alias notesArchiver='/home/poq/syncDir/gitRepos/gi.op.fo/miniProjects/2306_notesArchiver/notesArchiver.sh' #alias toJpg='/home/poq/syncDir/gitRepos/gi.op.fo/miniProjects/2306_toJpg/toJpg.sh' #imgResize() { diff --git a/dots/bin/notesArchiver.sh b/dots/bin/notesArchiver.sh new file mode 100644 index 0000000..3227743 --- /dev/null +++ b/dots/bin/notesArchiver.sh @@ -0,0 +1,63 @@ +#!/usr/bin/bash + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# what: archive (and backup) nextcloud notes +# author: ns +# started: jun 2023 +# +# requires: n/a +# +# info: +# - n/a +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +if [ "$EUID" -eq 0 ] + then echo "error: do not run as 'root'" + exit +fi + +nextcloud_env_var=NEXTCLOUD_${HOSTNAME} +nextcloud_dir=${!nextcloud_env_var} + +if [[ "${nextcloud_dir}" == "" ]]; then + echo "error: environment variable \"NEXTCLOUD_${HOSTNAME}\" is not set. set it, and re-run this script." + echo "example:" + echo "export NEXTCLOUD_${HOSTNAME}=/media/drive2/nass/lo/nextcloud" + exit 1 +fi + +notes_base_dir="${nextcloud_dir}/Notes" +notes_archive_dir="${nextcloud_dir}/Notes/archive" +archive_target_dir="${nextcloud_dir}/Notes.archive" +backup_target_dir="${nextcloud_dir}/Notes.backup" + +if [ ! -d ${backup_target_dir} ] +then + echo "The backup target directory does not exist:" + echo "${backup_target_dir}" + exit 888 # die with error code 888 +fi + +tar -zcvf ${backup_target_dir}/notes.$(date +%y%m%d-%H%M).tar.gz ${notes_base_dir} + +if [ ! -d ${notes_archive_dir} ] +then + echo "The archive directory does not exist:" + echo "${notes_archive_dir}" + exit 888 # die with error code 888 +fi + +# https://stackoverflow.com/questions/91368/checking-from-shell-script-if-a-directory-contains-files +if [ ! -n "$(ls -A ${notes_archive_dir} 2>/dev/null)" ] +then + echo "No notes to archive!" + exit 888 +fi + +# https://stackoverflow.com/questions/20796200/how-to-loop-over-files-in-directory-and-change-path-and-add-suffix-to-filename +# https://stackoverflow.com/questions/23733669/rename-file-command-in-unix-with-timestamp +for filename in ${notes_archive_dir}/*; do + mv "$filename" "$archive_target_dir/$(date +%y%m%d-%H%M)_$(basename "$filename")" +done + +echo 'Hello, World!' > ${notes_archive_dir}/helloWorld.md