Files
lnx-arch/dots/bin/obsolete/obsolete.notesArchiver.sh
committer@tuxwarrior 57e0ac6c96 archived notesArchiver.sh
imagine that…
2026-03-30 14:58:13 -05:00

64 lines
1.9 KiB
Bash
Executable File

#!/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