+ notesArchiver.sh

This commit is contained in:
committer@tuxwarrior
2026-02-26 14:57:45 -05:00
parent 17b0ab523c
commit 5d9ec65d9f
2 changed files with 63 additions and 1 deletions

View File

@@ -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() {

63
dots/bin/notesArchiver.sh Normal file
View File

@@ -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